This is a simple question:
I use the new support library, which allows me to have a Toolbar instance and even set it as the actionBar of the activity (or use the def
This is what I have done in one of my apps, it's showing shadow (artificial shadow) :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mainActivityLinearLayout"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent"
android:background="@drawable/logo">
<LinearLayout
android:layout_height="?attr/actionBarSize"
android:layout_width="match_parent"
android:orientation="vertical">
<!-- refer to your toolbar layout -->
<include layout="@layout/toolbar"/>
</LinearLayout>
<!-- My Left Drawer -->
<android.support.v4.widget.DrawerLayout
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/relative_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginStart="0dp"
android:layout_marginLeft="0dp" >
....
<!-- Lots of other stuffs -->
....
<!-- Shadow -->
<View
android:layout_width="match_parent"
android:layout_below="@+id/toolbarShadow"
android:layout_marginTop="0dp"
android:layout_height="6dp"
android:background="@drawable/toolbar_dropshadow" />
</RelativeLayout>
</android.support.v4.widget.DrawerLayout>
</LinearLayout>
toolbar_dropshadow.xml :
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape>
<gradient
android:angle="90"
android:startColor="@android:color/transparent"
android:endColor="#D6D6D6"
android:type="linear" />
</shape>
</item>
</selector>
I am using a map activity and all this is showing wonderful shadow on my map view.
Hope this helps...
As far as I know/can read, the AppCompat library currently does not render any shadows. The calls seem to be there (e.g. ViewCompat.setElevation(View view, float elevation)
) but it doesn't seem to be doing anything.
So I guess you will need to resort to adding your own shadows for now, at least until the support library implements the shadow rendering.
Looking at the Google IO 2014 source code, they have implemented like this:
More information on this Reddit Thread and stackoverflow.