Remove android.widget.Toolbar shadow

0leg picture 0leg · Apr 6, 2017 · Viewed 46.7k times · Source

Using API21+ Toolbar:

// Toolbar
Toolbar toolbar = new Toolbar(this);
toolbar.showOverflowMenu();

Would like to remove its shadow completely. setElevation(0) doesn't do anything since getElevation() already returns 0.

There is Material Design reference:

https://material.io/guidelines/layout/structure.html#structure-toolbars

There is Develop Reference:

https://developer.android.com/reference/android/widget/Toolbar.html

But I don't see any info related to the shadow. Toolbar

Question: how to remove/hide Toolbar shadow completely?

Answer

ramin eftekhari picture ramin eftekhari · Apr 6, 2017

Use app:elevation="0dp" instead of android:elevation on your toolbar. If it is not work, put your toolbar inside of a AppBarLayout and set app:elevation="0dp":

<android.support.design.widget.AppBarLayout
            android:id="@+id/appBarLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:elevation="0dp">
            ...
</android.support.design.widget.AppBarLayout>