Remove shadow below actionbar

2019-01-01 00:03发布

问题:

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?

回答1:

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


回答2:

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>


回答3:

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



回答4:

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



回答5:

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>


回答6:

You must set app:elevetor=\"0dp\" in android.support.design.widget.AppBarLayout and then it work :D

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


回答7:

app:elevation=\"0dp\" 

but not

android:elevation=\"0dp\"

worked for me on android L



回答8:

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


回答9:

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



回答10:

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.