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.
After more effort I can find my ideal Theme.
- First of all i must say that Theme.Holo.Light has a shadow in bottom of action bar if you want to have not that shadow you must use Theme.Holo.
After you change the style you must change other settings for yourself like the code.
<resources> <style name="AppTheme" parent="android:Theme.Holo"> <item name="android:actionBarStyle">@style/AppTheme.ActionBar</item> <item name="android:background">#ff0000</item> <item name="android:colorBackground">#ff0000</item> </style> <style name="AppTheme.ActionBar" parent="android:Widget.ActionBar"> <item name="android:background">#ff0000</item> </style> </resources>
This below code is for my last challange that I found how to resolve it.
<resources> <style name="AppTheme" parent="android:Theme.Holo.Light"> <item name="android:actionBarStyle">@style/AppTheme.ActionBar</item> <item name="android:background">#ff0000</item> <item name="android:colorBackground">#ff0000</item> </style> <style name="AppTheme.ActionBar" parent="android:Widget.ActionBar"> <item name="android:background">#ff0000</item> </style> </resources>
Below Image is for first Code, If you notice there isn't any divider.
- And below Image is for second Code.
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>
After more effort I can find my ideal Theme.
- First of all i must say that Theme.Holo.Light has a shadow in bottom of action bar if you want to have not that shadow you must use Theme.Holo.
After you change the style you must change other settings for yourself like the code.
<resources> <style name="AppTheme" parent="android:Theme.Holo"> <item name="android:actionBarStyle">@style/AppTheme.ActionBar</item> <item name="android:background">#ff0000</item> <item name="android:colorBackground">#ff0000</item> </style> <style name="AppTheme.ActionBar" parent="android:Widget.ActionBar"> <item name="android:background">#ff0000</item> </style> </resources>
This below code is for my last challange that I found how to resolve it.
<resources> <style name="AppTheme" parent="android:Theme.Holo.Light"> <item name="android:actionBarStyle">@style/AppTheme.ActionBar</item> <item name="android:background">#ff0000</item> <item name="android:colorBackground">#ff0000</item> </style> <style name="AppTheme.ActionBar" parent="android:Widget.ActionBar"> <item name="android:background">#ff0000</item> </style> </resources>
Below Image is for first Code, If you notice there isn't any divider.
- And below Image is for second Code.
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);
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.
This worked for me:
I just added the following line of code to the onCreate() method
getSupportActionBar().setElevation(0);
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>
In your styles.xml file , look for your AppTheme style and add the following style into it
<item name="android:actionBarDivider">@android:color/transparent</item>
like this
<style name="AppTheme" parent="Theme.AppCompat.Light">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:fontFamily">@font/roboto</item>
<item name="android:actionBarDivider">@android:color/transparent</item>
</style>
what it actually does is that it sets the background of the divider between activity window and action bar as transparent.
In case you are using AppBarLayout
nothing of that will help. I found the solution using :
AppBarLayout appBarLayout = findViewById(R.id.app_bar_layout);
appBarLayout.setOutlineProvider(null);
© 2022 - 2024 — McMap. All rights reserved.