I am using the toolbar from AppCompat V7 to replace the previous action bar and want to have a toolbar shadow like the previous action bar. but the toolbar by default has no shadow, and I tried the fixes mentioned in reddit . but no luck.
code to set the shadow:
mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
Toolbar layout:
<?xml version="1.0" encoding="utf-8"?> <android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android" android:minHeight="?attr/actionBarSize" android:background="#F1F1F1" android:layout_width="match_parent" android:layout_height="wrap_content" android:padding="0dp" android:layout_margin="0dp" foreground="?android:windowContentOverlay">
action plan:
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" tools:context=".MainActivity" android:layout_width="match_parent" android:id="@+id/drawer_layout" android:layout_height="match_parent"> <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent"> <include android:id="@+id/toolbar" layout="@layout/toolbar" /> <FrameLayout android:id="@+id/fragment_container" android:layout_below="@id/toolbar" android:layout_width="match_parent" android:layout_height="match_parent" /> </RelativeLayout> <RelativeLayout android:id="@+id/left_drawer" android:layout_gravity="start" android:layout_width="match_parent" android:background="#fff" android:layout_height="match_parent"> <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:paddingLeft="16dp" android:paddingRight="16dp" android:paddingTop="8dp" android:paddingBottom="8dp" android:divider="#eee" android:background="#EEE" android:id="@+id/drawer_header"> <ImageView android:id="@+id/user_icon" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="top" android:layout_alignParentTop="true" android:layout_alignParentLeft="true" android:contentDescription="@string/user_icon" android:src="@drawable/ic_action_person" android:paddingTop="0dp" android:paddingLeft="0dp"/> <TextView android:id="@+id/userName" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_toRightOf="@+id/user_icon" android:gravity="center" android:layout_gravity="center_vertical" android:layout_centerVertical="true" android:textSize="14sp" android:text="@string/not_logged_in" android:paddingTop="0dp" android:paddingBottom="0dp"/> </RelativeLayout> <ListView android:id="@+id/drawer_list" android:layout_below="@+id/drawer_header" android:layout_width="match_parent" android:layout_height="wrap_content" android:divider="#eee" android:background="#fff" android:dividerHeight="0dp" /> </RelativeLayout> </android.support.v4.widget.DrawerLayout>
Setting in style.xml file:
<style name="myAppTheme" parent="Theme.AppCompat.Light"> <item name="colorPrimary">@color/primaryColor</item> <item name="colorPrimaryDark">@color/primaryColorDark</item> <item name="android:windowNoTitle">true</item> <item name="windowActionBar">false</item> <item name="drawerArrowStyle">@style/DrawerArrowStyle</item> <item name="android:windowContentOverlay">@drawable/drawer_shadow</item> </style> <style name="DrawerArrowStyle" parent="Widget.AppCompat.DrawerArrowToggle"> <item name="spinBars">true</item> <item name="color">@android:color/black</item> </style>
Can anyone help?
thanks!
update 1: with Willis's suggestion, I get a shadow, but itβs not under the toolbar, but on the left of the toolbar. 
Update 2: I noticed that if I don't set windowContentOverlay to toolbar.xml and styles.xml, the shadow is actually at the top of the toolbar. 
android material-design appcompat android-toolbar
Martin lau
source share