Android action bar tab selector color changes when changing or folded

I have an action bar configured using tab navigation. On the smaller screens, the tabs are below the action bar, and the larger screens are the tabs inside the action bar. My action bar is colored red and the tabs are black. When the tabs are below the action bar, I would like the selector to be colored red and then change the color to black if the tabs are inside the action bar.

My problem is that I either get a red selector both below and inside the action bar, or a black selector both below and inside the action bar. When the tabs are below the action bar, I would like the selector to be red, and when it is inside, I would like the selector to be black. Here is my styles_actionbar.xml:

<style name="Theme.customabthemegenerated" parent="@android:Theme.Holo.Light"> <item name="android:actionBarItemBackground">@drawable/selectable_background_customabthemegenerated</item> <item name="android:actionBarStyle">@style/solid_ActionBar</item> <item name="android:actionBarTabStyle">@style/ActionBarTabStyle</item> <item name="android:actionBarTabBarStyle">@style/ActionBarTabBarStyle</item> <item name="android:actionBarTabTextStyle">@style/ActionBarText</item> </style> <style name="solid_ActionBar" parent="@android:Widget.Holo.Light.ActionBar.Solid"> <item name="android:background">@drawable/ab_solid_customabthemegenerated</item> <item name="android:backgroundStacked">@drawable/ab_stacked_solid_customabthemegenerated</item> <item name="android:backgroundSplit">@drawable/ab_bottom_solid_customabthemegenerated</item><!-- No difference without it --> </style> <style name="ActionBarTabStyle" parent="@android:style/Widget.Holo.ActionBar.TabView"> <item name="android:background">@drawable/tab_indicator_inside</item> </style> <style name="ActionBarTabBarStyle" parent="@android:style/Widget.Holo.ActionBar.TabBar"> <item name="android:background">@drawable/tab_indicator_outside</item> </style> <style name="ActionBarText" parent="@android:style/TextAppearance"> <item name="android:textColor">@color/white</item> </style> 

I thought ActionBarTabBarStyle would style the tabs when they are outside the action bar, but it seems to have no effect. Is there a way to get the red selector when the action bar is split, and the black selector when the action bar is folded?

+2
source share
1 answer

I was able to do this by providing a different style when the screen width is above 480dp. Screens smaller than this are considered narrow, and the action bar is divided (and the tabs are in the stacked panel).

To do this, create a resource file res/values-w480dp/style.xml and define the style of your tabs when they are combined in the action bar. In the usual res/values-w480dp/style.xml define the style for your tabs when they are in the addition action bar.

This will only work for SDK> 13.

This is not a very clean solution, but it still works.

+3
source

All Articles