Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing bottom shadow on ActionBar - Android

I want to disable ActionBar shadow but only in one Activity. If I use this code it will be change in whole aplication.

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

I tried this code, but it is not working

getSupportActionBar().setElevation(0);

Any suggestion...?

like image 640
KiKo Avatar asked Nov 27 '14 12:11

KiKo


1 Answers

You can set your own style for Activity for this:

<!-- Your main theme with ActionBar shadow. -->
<style name="MyAppTheme" parent="android:Theme.Holo.Light">
    ....
</style>

<!-- Theme without ActionBar shadow (inherits main theme) -->
<style name="MyNoActionBarShadowTheme" parent="MyAppTheme">
    <item name="windowContentOverlay">@null</item>
    <item name="android:windowContentOverlay">@null</item>
</style>

So in Manifest.xml you can set different style for all Activities:

<!-- Activity with ActionBar shadow -->
<activity
    android:name=".ShadowActivity"
    android:theme="@style/MyAppTheme"/>

<!-- Activity without ActionBar shadow -->
<activity
    android:name=".NoShadowActivity"
    android:theme="@style/MyNoActionBarShadowTheme"/>

Or you can set the right theme programmatically in onCreate() method:

@Override
protected void onCreate(Bundle savedInstanceState) {
    setTheme(R.style.MyNoActionBarShadowTheme);
    super.onCreate(savedInstanceState);

    //...
}
like image 147
Suvitruf - Andrei Apanasik Avatar answered Sep 21 '22 00:09

Suvitruf - Andrei Apanasik