Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change Elevation of ActionBar by theme

I want to remove the shadow below the ActionBar.

I know that I need to change the elevation to 0dp, but I want to do it in the theme.

For Android 4.4- I use : <item name="android:windowContentOverlay">@null</item>

But is it possible for Android 5.0 ?

like image 491
Stephane Mathis Avatar asked Jan 15 '15 09:01

Stephane Mathis


People also ask

How do I customize my action bar?

This example demonstrate about how to create a custom action bar in Android. 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. xml.

What is default elevation for toolbar?

The default elevation of the action bar is 4dp.


1 Answers

As shown by Antonio Jose, here is an answer : Remove shadow below actionbar


For Android 5.0, if you want to set it directly into a style use:

<item name="android:elevation">0dp</item>

and for Support library compatibility use:

<item name="elevation">0dp</item>

Example of style for a AppCompat light theme:

<style name="Theme.MyApp.ActionBar" parent="style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<!-- remove shadow below action bar -->
<!-- <item name="android:elevation">0dp</item> -->
<!-- Support library compatibility -->
<item name="elevation">0dp</item>
</style>

Then apply this custom ActionBar style to you app theme:

<style name="Theme.MyApp" parent="Theme.AppCompat.Light">
    <item name="actionBarStyle">@style/Theme.MyApp.ActionBar</item>
</style>

For pre 5.0 Android, add this too to your app theme:

<!-- Remove shadow below action bar Android < 5.0 -->
<item name="android:windowContentOverlay">@null</item>
like image 187
Stephane Mathis Avatar answered Sep 20 '22 07:09

Stephane Mathis