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.
Use attribute app:elevation="0dp" to your Toolbar or AppBarLayout to remove the shadow. #. If you are using Toolbar only, then add attribute app:elevation="0dp" to Toolbar .
By default, android provides shadow for action bar. This example demonstrates How to remove shadow below the action bar. Step 1 - Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 - Add the following code to res/layout/activity_main.
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:
<!-- Your main theme with ActionBar shadow. -->
<style name="MyTheme" parent="Theme.Sherlock">
....
</style>
<!-- Theme without ActionBar shadow (inherits main theme) -->
<style name="MyNoActionBarShadowTheme" parent="MyTheme">
<item name="windowContentOverlay">@null</item>
<item name="android:windowContentOverlay">@null</item>
</style>
Now you can set them to activities in AndroidManifest.xml
:
<!-- Activity with ActionBar shadow -->
<activity
android:name=".ShadowActivity"
android:theme="@style/MyTheme"/>
<!-- 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);
//...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With