Ersen Osman Ersen Osman - 1 month ago 53
Android Question

Android: I cannot remove elevation / shadow on my toolbar

Hi i would like to remove the elevation and shadow effect from my toolbar for API 21 and greater. Below is what i have tried

setSupportActionBar(mToolbar);
getSupportActionBar().setDisplayShowTitleEnabled(false);
getSupportActionBar().setElevation(0);


My Toolbar in XML. I have tried to set elevation to 0dp

<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimary"
android:minHeight="?attr/actionBarSize"
android:elevation="0dp"
android:theme="@style/ToolbarStyle"
app:theme="@style/ToolbarStyle"
>


And this is ToolbarStyle if it helps

<style name="ToolbarStyle" parent="ThemeOverlay.AppCompat.Dark">
<item name="colorControlNormal">@android:color/white</item>
</style>


Edit 1: Tried the following in styles v21. Still same result

<style name="ToolbarStyle" parent="ThemeOverlay.AppCompat.Dark">
<item name="colorControlNormal">@android:color/white</item>
<item name="android:elevation">0dp</item>
</style>


Edit 2: Where the toolbar is in my layout

android.support.v4.widget.DrawerLayout

xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">

<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">

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

<include layout="@layout/toolbar" />

Answer

You can do that with an easy step. Don't remove the android.support.design.widget.AppBarLayout from your layout, instead add the attribute app:elevation="0dp" to it. Your final layout will be:

<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>
Comments