Remove shadow below actionbar

AndroidAndroid ActionbarActionbarsherlock

Android Problem Overview


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?

Android Solutions


Solution 1 - Android

> 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);

Solution 2 - Android

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>

Solution 3 - Android

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

Solution 4 - Android

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

Solution 5 - Android

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>

Solution 6 - Android

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>

Solution 7 - Android

app:elevation="0dp" 

but not

android:elevation="0dp"

worked for me on android L

Solution 8 - Android

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);
    .
    .
    }

Solution 9 - Android

Solution for Kotlin (Android 3.3, Kotlin 1.3.20)

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    supportActionBar!!.elevation = 0f
}

Solution 10 - Android

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

Solution 11 - Android

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>

Solution 12 - Android

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.

Solution 13 - Android

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.

Solution 14 - Android

Use:

outLineAmbientShadowColor="@null"

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMichał KlimczakView Question on Stackoverflow
Solution 1 - AndroidTomer MorView Answer on Stackoverflow
Solution 2 - AndroidSlooshView Answer on Stackoverflow
Solution 3 - AndroidKieronView Answer on Stackoverflow
Solution 4 - AndroidVijay VavdiyaView Answer on Stackoverflow
Solution 5 - AndroidDmitry ZaytsevView Answer on Stackoverflow
Solution 6 - AndroidNguyên PhạmView Answer on Stackoverflow
Solution 7 - AndroidYTerleView Answer on Stackoverflow
Solution 8 - Androidshubham guptaView Answer on Stackoverflow
Solution 9 - AndroidzeeshanView Answer on Stackoverflow
Solution 10 - AndroidBYISHIMO AudaceView Answer on Stackoverflow
Solution 11 - AndroidRahulView Answer on Stackoverflow
Solution 12 - AndroidCollins USHIView Answer on Stackoverflow
Solution 13 - AndroidBowie ChangView Answer on Stackoverflow
Solution 14 - AndroidHossein EyvaziView Answer on Stackoverflow