How can i remove the drop shadow of action bar from java code ?.
If i remove from the style it is working fine.
<style name="MyTheme" parent="Theme.Sherlock">
....
<item name="windowContentOverlay">@null</item>
<item name="android:windowContentOverlay">@null</item>
....
</style>
But i need to remove and add it dynamically from java code.
I know this question is old, but this problem was new for me, so it might help somebody else as well.
Try:
getSupportActionBar().setElevation(0)
;Or, if you are not using a custom action bar:
getActionBar().setElevation(0)
;I think this is the easiest way to do it programmatically.
Define a new style like this. Notice that there's no parent defined:
Add this above your code:
There is no way to set value for
windowContentOverlay
attribute programmatically. But you can define two different themes, one for Activities with a visible ActionBar shadow and one for others:Now you can set them to activities in
AndroidManifest.xml
:Or you can set the right theme programmatically in
onCreate()
method:If
supportActionBar.elevation=0f
did not work for you, You can remove the shadow by settingappBar.targetElevation=0f
but this method is deprecated. The new method is using StateListAnimator.You have to set the
stateListAnimator
toAppBarLayout
without elevation that can be achieved by the steps belowCreate animator resource
appbar_animator.xml
android.valueTo="0dp"
defines the elevation.Inflate and set the
StateListAnimator
toappBar
StateListAnimator was added in api
21
LollipopDeclare 2 styles ne has a shadow and the other one doesn't. THen in your manifest define each activity's theme with respective one. e.g
I found this article: Change Theme of Layout Runtime by Button Click in Android
It allows you to change the theme of an activity, but it does call finish() and restart the activity. So, I am not sure it will work for what you want.