219

I use actionbarsherlock. The piece of code below is responsible for changing it's background to a custom one.

<style name="Widget.Styled.ActionBar" parent="Widget.Sherlock.ActionBar">
    <item name="background">@drawable/actionbar_bg</item>
    <item name="android:background">@drawable/actionbar_bg</item>
    <...>  
</style>

<style name="Theme.MyApp" parent="@style/Theme.Sherlock.Light">
    <item name="actionBarStyle">@style/Widget.Styled.ActionBar</item>
    <item name="android:actionBarStyle">@style/Widget.Styled.ActionBar</item>
    <..>
</style>

And it works for actionbarsherlock (on versions below honeycomb). But in ICS I have a shadow below actionbar which I don't want. What is the style item to make it disappear?

Michał Klimczak
  • 12,674
  • 8
  • 66
  • 99

14 Answers14

496

What is the style item to make it disappear?

In order to remove the shadow add this to your app theme:

<style name="MyAppTheme" parent="android:Theme.Holo.Light">
    <item name="android:windowContentOverlay">@null</item>
</style>

UPDATE: As @Quinny898 stated, on Android 5.0 this has changed, you have to call setElevation(0) on your action bar. Note that if you're using the support library you must call it to that like so:

getSupportActionBar().setElevation(0);
Mangesh
  • 5,491
  • 5
  • 48
  • 71
Tomer Mor
  • 7,998
  • 5
  • 29
  • 43
  • Isn't it a style to remove the shadow from below the status bar, not the actionbar? – Michał Klimczak Sep 03 '12 at 11:07
  • 97
    Thanks, it disappeared. Important thing to note is that this line of code should appear in the app theme, not the actionbar style. – Michał Klimczak Sep 03 '12 at 11:37
  • 3
    I works! What need be clear is that this line of code should be added in the App Theme Tag, not the ActionBar Theme tag. – tuoxie007 Jun 18 '14 at 07:13
  • And another thing that also should be noted is that you should change your theme in values,values-v11,value-v14 (if you use toolbar ,ignore this) – TheOne_su Apr 20 '15 at 05:46
  • for pre-lollipop , is it possible to do it only in code instead of using XML ? – android developer Jun 18 '15 at 14:34
  • 6
    for pre-lollipop devices `getSupportActionBar().setElevation(0);` doesn't work. So you've put `@null` in your application theme. I had the similar problem. Now I've both of them. setElevation from and added windowContentOverlay item in application theme. setElevation works for android 5.0 and up while the other works for pre-lollipop. Cheers! – Reaz Murshed Jul 15 '15 at 07:06
  • Thank you very much. It works. As mentioned by the others, the code needs to be put inside the AppTheme, not the ActionBarTheme. – stanley santoso Aug 26 '15 at 17:37
  • 1
    Important to note, when using `getSupportActionBar().setElevation(0);`, you must call this before `setContentView()` for this to work. – levibostian Sep 22 '15 at 00:28
147

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>
sourcerebels
  • 5,140
  • 1
  • 32
  • 52
Sloosh
  • 1,681
  • 1
  • 10
  • 14
  • 1
    Did not work for me for pre 5.0 devices. The problem was, I added the `windowContentOverlay` to the action bar theme, not to the app theme. – Oliv Aug 27 '15 at 08:08
  • 1
    I'm sorry but im trying to do the opposite thing, Make the elevation shadow actually appear on pre-lollipop devices (I've managed to do it with `android:elevation` for Lollipop devices). I can't manage to do it, using this approach. I believe it would be fairly straight. Put a non-zero value for elevation attributes and thats would be it. – acrespo Oct 08 '15 at 00:11
  • It should be visible by default if you don't touch android:windowContentOverlay attribute, maybe check that you are using a correct theme... I think you need to use an AppCompat theme. – Sloosh Oct 09 '15 at 07:08
  • but how to deal with `android:windowContentOverlay` on pre lollipop API? I cannot compile if my minSDK is pre lollipop but target is 21? – Opiatefuchs Apr 25 '16 at 06:33
  • You should be able to compile. Maybe try to target 22 or 23 instead if possible. – Sloosh Apr 25 '16 at 09:06
  • @Sloosh can we do this programmatically? – Saeed Jassani Dec 31 '16 at 12:19
  • 2
    This worked but only when I used ` – Igor May 21 '18 at 22:35
  • This worked for `actionBarStyle`, but not working for `actionBarTheme`. Why is that so? – Vadim Kotov Feb 14 '19 at 11:00
104

On Android 5.0 this has changed, you have to call setElevation(0) on your action bar. Note that if you're using the support library you must call it to that like so:

getSupportActionBar().setElevation(0);

It's unaffected by the windowContentOverlay style item, so no changes to styles are required

Kieron
  • 1,982
  • 2
  • 18
  • 17
  • 1
    Do you have to do this for every activity, or is there a quick method for it to apply to all activities? I will add this all my activities for now. Thanks! – cnfw Nov 19 '14 at 23:10
  • As it's like any other actionbar method (eg. the title), I'd say every activity – Kieron Nov 20 '14 at 18:42
  • That's a shame. It would be nice to set parameters like this in the styles.xml file. Maybe that will come in a future update – cnfw Nov 20 '14 at 22:34
  • this is not working on lower versions than 5.0. Isn't the support actionbar supposed to be compatible with all previous devices? – splinter123 Mar 22 '15 at 22:05
  • same as @splinter123 here :( Wonder how I can remove the shadows on pre-Lollipop when using AppCompat. – FD_ May 20 '15 at 09:51
  • Have a look at at my solution above, it explains how to do with pre-Lollipop and AppCompat. – Sloosh Oct 09 '15 at 07:04
  • this works but then, I have a back arrow in the actionbar, which is not receiving any input. Any ideas on how to solve this ? – techtinkerer Feb 19 '16 at 09:09
  • it is not work for me on custom Toolbar. I create a Custom toolbar in xml and add it to SupportAction bar – Mahdi Nov 21 '16 at 09:41
56

add app:elevation="0dp" in AppBarLayout for hiding shadow in appbar

Vijay Vavdiya
  • 1,249
  • 13
  • 17
39

If you are working with ActionBarSherlock

In your theme add this:

<style name="MyTheme" parent="Theme.Sherlock">
    ....
    <item name="windowContentOverlay">@null</item>
    <item name="android:windowContentOverlay">@null</item>
    ....
</style>
Dmitry Zaytsev
  • 23,650
  • 14
  • 92
  • 146
30

You must set app:elevation="0dp" in the android.support.design.widget.AppBarLayout and then it works.

<android.support.design.widget.AppBarLayout
    app:elevation="0dp"... >

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="@android:color/transparent"
        app:popupTheme="@style/AppTheme.PopupOverlay" >


    </android.support.v7.widget.Toolbar>

</android.support.design.widget.AppBarLayout>
Cindy Meister
  • 25,071
  • 21
  • 34
  • 43
Nguyên Phạm
  • 441
  • 5
  • 2
  • 1
    this causes, that the shadow of the AppBar is away everywhere - how can I control that programmatically? – Suisse Nov 19 '16 at 15:32
19
app:elevation="0dp" 

but not

android:elevation="0dp"

worked for me on android L

YTerle
  • 2,606
  • 6
  • 24
  • 40
3

I have this same problem, and I have successfully solved this problem. All you have to do is just change the elevation to 0 floating point value in that activity in which you want to remove the elevation.

If you want to change it in an activity called MyActivity.java so you have to get the ActionBar first.

First import the ActionBar class

import android.support.v7.app.ActionBar;

after importing you have to initialize a variable of action bar and set its elevation to 0.

 private ActionBar toolbar;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
    .
    .
    toolbar=getSupportActionBar();
    toolbar.setElevation(0);
    .
    .
    }
2

Solution for Kotlin (Android 3.3, Kotlin 1.3.20)

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    supportActionBar!!.elevation = 0f
}
zeeshan
  • 4,913
  • 1
  • 49
  • 58
1

For Xamarin Developers, please use : SupportActionBar.Elevation = 0; for AppCompatActivity or ActionBar.Elevation = 0; for non-compat Activities

BYISHIMO Audace
  • 585
  • 1
  • 8
  • 18
1

Try This it helped me without changing theme . Put Your AppBarLayout inside any layout.Hope this will help you

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
<android.support.design.widget.AppBarLayout
    android:id="@+id/app_bar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:fitsSystemWindows="false"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">


    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
        android:layout_height="?attr/actionBarSize"
       android:background="@color/white">
        <ImageView
            android:src="@drawable/go_grocery_logo"
            android:layout_width="108dp"
            android:layout_height="32dp" />
    </android.support.v7.widget.Toolbar>


</android.support.design.widget.AppBarLayout>
</RelativeLayout>
Rahul
  • 99
  • 6
1

Add this toolbar.getBackground().setAlpha(0); to inside OnCreate method. The add this: android:elevation="0dp" android:background="@android:color/transparent to your toolbar xml file.

Collins USHI
  • 567
  • 7
  • 17
0

For those working on fragments and it disappeared after setting toolbar.getBackground().setAlpha(0); or any disappearance, i think you have to bring your AppBarLayout to the last in the xml, so its Fragment then AppBarLayout then relativelayout/constraint/linear whichever u use.

Bowie Chang
  • 126
  • 12
0

Use:

outLineAmbientShadowColor="@null"
Timus
  • 10,974
  • 5
  • 14
  • 28