How To Make Android Toolbar Elevation Working On Pre-Lollipop Devices
Step 1.
Make a material toolbar. (How To Make Material Design Actionbar/Toolbar In 7 Simple Steps)
Step 2.
- <?xml version="1.0" encoding="utf-8"?>
- <shape android:shape="rectangle" xmlns:android="http://schemas.android.com/apk/res/android">
- <gradient
- android:startColor="@android:color/transparent"
- android:endColor="#40000000"
- android:angle="90"/>
- </shape>
Step 3.
Open "activity_main.xml" and add these lines between "include" and "RelativeLayout" Tags.
- <FrameLayout
- android:layout_width="fill_parent"
- android:layout_height="4dp"
- android:background="@drawable/shadow"
- android:layout_below="@+id/toolbar"
- android:visibility="invisible" />
- <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:tools="http://schemas.android.com/tools"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- tools:context=".MainActivity">
- <include
- android:id="@+id/toolbar"
- layout="@layout/toolbar"/>
- <FrameLayout
- android:layout_width="fill_parent"
- android:layout_height="4dp"
- android:background="@drawable/shadow"
- android:layout_below="@+id/toolbar"
- android:visibility="invisible" />
- <RelativeLayout
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:layout_alignParentLeft="true"
- android:layout_alignParentStart="true"
- android:layout_below="@+id/toolbar"
- android:layout_alignParentRight="true"
- android:layout_alignParentEnd="true"
- android:layout_alignParentBottom="true"
- android:paddingLeft="@dimen/activity_horizontal_margin"
- android:paddingTop="@dimen/activity_vertical_margin"
- android:paddingRight="@dimen/activity_horizontal_margin"
- android:paddingBottom="@dimen/activity_vertical_margin">
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="@string/hello_world"
- android:id="@+id/textView16" />
- </RelativeLayout>
- </RelativeLayout>
Comments
Post a Comment