Search code examples
androidandroid-actionbarandroid-actionbar-compat

Remove action bar shadow


I want to remove the shadow that appears below the appcompat action bar so that the background of the action bar is completely transparent.

This is my theme and action bar style:

<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>

    <item name="android:actionBarStyle">@style/TransparentActionBar</item>
    <item name="android:windowActionBarOverlay">true</item>

    <!-- Support library compatibility -->
    <item name="actionBarStyle">@style/TransparentActionBar</item>
    <item name="windowActionBarOverlay">true</item>

</style>

<!-- Transparent Action Bar Style -->
<style name="TransparentActionBar"
    parent="Widget.AppCompat.Light.ActionBar.Solid.Inverse">
    <item name="android:background">@android:color/transparent</item>

    <!-- Support library compatibility -->
    <item name="background">@android:color/transparent</item>
    <item name="elevation">0dp</item>
</style>

My minimum API level is 16

I've tried several solutions for this including:

  • Setting elevation to 0dp only works for Lollipop devices.
  • I get a "resource not found" error if I try to use windowContentOverlay
  • Setting the background of the root view to a color like white or transparent doesn't work

I've been trying to get this to work on 4.4.4 to no avail. Is it not possible below API level 21?

EDIT:

it turns out that the windowContentOverlay only works with the android prefix:

<item name="android:windowContentOverlay">@null<item/>

Trying to also define it without the prefix results in the resource not found error (this error points to the one with the prefix for whatever reason). I honestly don't understand why this occurs. I can only assume appcompat doesn't support the windowContentOverlay attribute.


Solution

  • Set windowContentOverlay to a drawable that will be drawn under the action bar. If you don't want a shadow set it to null, like so:

    <item name="android:windowContentOverlay">@null</item>
    

    and

    <item name="windowContentOverlay">@null</item>
    

    This works API level 16 and up.