Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: I cannot remove elevation / shadow on my toolbar

Tags:

android

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" /> 
like image 509
Ersen Osman Avatar asked Jul 06 '15 13:07

Ersen Osman


People also ask

How do I get rid of the shadow bar on my android?

By default, android provides shadow for action bar. This example demonstrates How to remove shadow below the action bar. Step 1 - Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 - Add the following code to res/layout/activity_main.

What is above toolbar in android?

View above the Toolbar is officially know as status bar in android and to change color of status bar check out the answer of this question How to change the status bar color in android.


1 Answers

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> 
like image 98
Filipe Bezerra de Sousa Avatar answered Sep 17 '22 19:09

Filipe Bezerra de Sousa