Removing line or divider between action bar and main screen in Android
Solution 1
Simply insert the attribute windowContentOverlay to your theme. It's way too simple this way.
<style name="AppTheme" parent="android:Theme.Holo.Light">
<!-- Customize your theme here. -->
<item name="android:windowContentOverlay">@null</item>
</style>
Solution 2
On Kotlin, you can use supportActionBar?.elevation = 0f
to remove the shadow of the ActionBar.
Add this code to the onCreate()
function of the desired activity. For example:
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
// Hide ActionBar shadow
supportActionBar?.elevation = 0f
}
The ?.
operator controls Null Pointer Exception if you have no ActionBar on this Activity.
Note: If you are not using AppCompat, call actionBar?.elevation = 0f
instead.
Solution 3
None of these solutions worked for me. I ended up adding this code to the onCreate()
event of my MainActivity
:
actionBar = getSupportActionBar();
actionBar.setElevation(0);
Solution 4
If you use AppCompat you need set parent="Theme.AppCompat", not "Theme.AppCompat.Light" (the same stands for ActionBar) :)
For example: @style/MyActionBar true @style/MyActionBar true
<style name="MyActionBar" parent="Base.Widget.AppCompat.ActionBar">
<item name="android:background">@android:color/transparent</item>
<!--For compatibility-->
<item name="background">@android:color/transparent</item>
</style>
Solution 5
This worked for me:
I just added the following line of code to the onCreate() method
getSupportActionBar().setElevation(0);
Admin
Updated on June 27, 2022Comments
-
Admin almost 2 years
How can I remove line or divider between action bar and main screen? How can I change the color of this divider in android? Thanks in advance.
-
yahya almost 9 yearsThis removes only the shadow, not the line