Skip to content

Instantly share code, notes, and snippets.

@germankatz
Last active December 8, 2015 04:30
Show Gist options
  • Save germankatz/e40628fcda9c6e903c07 to your computer and use it in GitHub Desktop.
Save germankatz/e40628fcda9c6e903c07 to your computer and use it in GitHub Desktop.
Shadow on toolbar for pre-lollipop devices

Shadow on toolbar for pre-lollipop devices

First, this is the basic layout for the activity/fragment:

<LinearLayout 
	xmlns:android="http://schemas.android.com/apk/res/android"
	xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="top"
    android:orientation="vertical">

    <android.support.v7.widget.Toolbar 
    		xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/myPrimaryColor"
        android:titleTextAppearance="@color/White"
        app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <!-- **** Content here **** -->

        <View
            android:layout_width="match_parent"
            android:layout_height="5dp"
            android:background="@drawable/toolbar_shadow" />
    </FrameLayout>
</LinearLayout>

Then, you should create the shadow file:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<gradient
    android:startColor="@android:color/transparent"
    android:endColor="#88333333"
    android:angle="90"/>
</shape>

And that's all folks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment