I'm updating my app with the new Toolbar from the support library v21. My problem is that the toolbar does not cast any shadow if I don't set the "elevation" attribute. Is that the normal behavior or I'm doing something wrong?
My code is:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/my_awesome_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:elevation="4dp"
android:minHeight="?attr/actionBarSize"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
<FrameLayout
android:id="@+id/FrameLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent">
.
.
.
And in my Activity - OnCreate method:
Toolbar toolbar = (Toolbar) findViewById(R.id.my_awesome_toolbar);
setSupportActionBar(toolbar);
For 5.0 + : You can use AppBarLayout with Toolbar. AppBarLayout has "elevation" attribure.
Was toying with this for hours, here's what worked for me.
Remove all the
elevation
attributes from theappBarLayout
andToolbar
widgets (includingstyles.xml
if you are applying any styling).Now inside activity,apply the
elvation
on youractionBar
:This should work.
Google released the Design Support library a few weeks ago and there is a nifty solution for this problem in this library.
Add the Design Support library as a dependency in
build.gradle
:Add
AppBarLayout
supplied by the library as a wrapper around yourToolbar
layout to generate a drop shadow.Here is the result :
There are lots of other tricks with the design support library.
i added
in toolbar description and it works for me. Using 5.0+
I ended up setting my own drop shadow for the toolbar, thought it might helpful for anyone looking for it:
@drawable/toolbar_dropshadow:
@color/color_alizarin
This worked for me very well: