Using the CardView container for a toolbar is a bad idea.
CardView is heavy, especially for low-maintenance devices.
The best way is to place a gradient view of the shadows under the toolbar under the tensor. The shadow view should be a direct child in the layout of the coordinator. i.e. An application bar containing a toolbar and shadow view must be siblings.
Add this view component to your layout.
<View android:id="@+id/gradientShadow" android:layout_width="match_parent" android:layout_height="5dp" android:background="@drawable/toolbar_shadow" app:layout_behavior="@string/appbar_scrolling_view_behavior" app:layout_collapseMode="pin"/>
Selectable toolbar_shadow.xml
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <gradient android:angle="90" android:endColor="#33333333" android:startColor="@android:color/transparent"/> </shape>
This will solve problems in devices with preliminary Lellipop. But we donβt want this shadow to be on candy and above, so you can see the visibility on devices with candy and above.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { findViewById(R.id.gradientShadow).setVisibility(View.GONE); }
Done.
shijin Jun 02 '16 at 6:36 2016-06-02 06:36
source share