I used this code to change the Color of ActionBarSherlock:
<style name="Theme.MyTheme" parent="Theme.Sherlock.Light.DarkActionBar">
<!-- set style for action bar (affects tab bar too) -->
<item name="actionBarStyle">@style/Widget.MyTheme.ActionBar</item>
<item name="android:actionBarStyle">@style/Widget.MyTheme.ActionBar</item>
<!-- define text style for tabs -->
<item name="actionBarTabTextStyle">@style/MyTheme.ActionBar.TabText</item>
<item name="android:actionBarTabTextStyle">@style/MyTheme.ActionBar.TabText</item>
</style>
<style name="Widget.MyTheme.ActionBar" parent="Widget.Sherlock.ActionBar">
<!-- define background for action bar (sets default for all parts of action bar - main, stacked, split) -->
<item name="android:background">#blue</item>
<item name="background">#blue</item>
<item name="android:titleTextStyle">@style/MyTheme.ActionBar.TitleTextStyleWhite</item>
<item name="titleTextStyle">@style/MyTheme.ActionBar.TitleTextStyleWhite</item>
<!-- set background for the tab bar (stacked action bar) - it overrides the background property -->
<item name="android:backgroundStacked">#grey</item>
<item name="backgroundStacked">#grey</item>
</style>
<style name="MyTheme.ActionBar.TabText" parent="Widget.Sherlock.ActionBar.TabText">
<item name="android:textColor">#black</item>
</style>
<style name="MyTheme.ActionBar.TitleTextStyleWhite" parent="@android:style/TextAppearance.Holo.Widget.ActionBar.Title">
<item name="android:textColor">#white</item>
</style>
as suggested by Jake Warton here:
Change ActionBarSherlock background color
But the thing is the ActionBar and Tabs both change to Blue color. I actually want to change The top actionBar background to Blue and Tabs background to White
how to do this?
Thank You
There are two ways how you can change background of the tab bar:
1) If you are using tabs only in portrait orientation, you can set
backgroundStacked
(andandroid:backgroundStacked
) item of(android:)actionBarStyle
. It sets the background for stacked action bar (the tab bar).Your theme has to contain:
The
ActionBarStyle
then has to be:That's all you have to do. But this solution won't work in landscape. In landscape the tabs can be moved to the main action bar.
2) If you are using tabs in both portrait and landscape orientation, a different solution has to be used.
The theme has to contain:
And set background for the tab bar style:
Note: If you try to combine both approaches, then the background from
actionBarTabBarStyle
will be placed over the background frombackgroundStacked
.Note: These two approaches sets background for the whole tab bar, setting the background for a single tab in tab bar is different.
Tab text color
If you want to set text color for the tabs you have to define
actionBarTabTextStyle
.The theme has to contain:
The tab text style is then:
Use ActionbarStyleGenerator to change the color of what all you need. This is by far the simplest and most intuitive way.
How to: