ActionBar styling different tab background when below ActionBar
-
21-12-2019 - |
Question
Is there a way to define ActionBar
tab style so that it would have different backgrounds when tabs are in ActionBar
and below it?
I can't seem to find a way to do that with theme configuration with these properties
<item name="android:actionBarTabStyle">@style/Custom.ActionBar.TabView</item>
<item name="android:actionBarTabBarStyle">@style/Custom.ActionBar.TabBar</item>
<item name="android:actionBarTabTextStyle">@style/Custom.ActionBar.TabText</item>
I can define tab background to be white in @style/Custom.ActionBar.TabBar
. All is ok with ActionBar.NAVIGATION_MODE_TABS
.
But when I switch to ActionBar.NAVIGATION_MODE_LIST
it is placed inside ActionBar
and it also becomes white. And thats is unwanted behavior.
Solution
You can control the behaviors and visibility of the action bar with the ActionBar APIs, which were added in Android 3.0 (API level 11)."
So, ActionBar will not work for your target environment which is at API level 10 (Android 2.3.3).
Just in case, if you target for minimum API level 11 , you can change ActionBar's background color by defining custom style, as:
<resources>
<style name="MyTheme" parent="@android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">@style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="@android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">ANY_HEX_COLOR_CODE</item>
</style>
</resources>
And, set "MyTheme" as theme for application / activity.
Hope this helps...