Change the background only to ActionBarSherlock. Not tabs

I used this code to change the color of an 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 Jake Warton suggested here:

Change background color of ActionBarSherlock

But the fact is that ActionBar and Tabs change color to Blue . I really want to change the top background of the ActionBar to blue and the background of the tab to white

how to do it?

thank

+2
android actionbarsherlock
Nov 07
source share
2 answers

Use ActionbarStyleGenerator to change the color of everything you need. This is by far the easiest and most intuitive way.

How to do:

  • Use the user interface to select colors for different elements.
  • After that, click on the download button .zip
  • ZIP will contain resource files under the necessary folders, which must be copied in the res / layout and res / drawableXXXX folders.
+6
Nov 08
source share

There are two ways to change the background of the tab bar:

1) If you use tabs only in portrait orientation, you can set the backgroundStacked (and android:backgroundStacked ) element (android:)actionBarStyle . It sets the background for a complex action bar (tab bar).

Your topic should contain:

 <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> </style> 

Then the ActionBarStyle should be:

 <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">#ff0000ff</item> <item name="background">#ff0000ff</item> <!-- set background for the tab bar (stacked action bar) - it overrides the background property --> <item name="android:backgroundStacked">#ffff</item> <item name="backgroundStacked">#ffff</item> </style> 

That is all you need. But this solution will not work in the landscape. In the landscape, tabs can be moved to the main action bar.

2) If you use tabs in both portrait and landscape orientation, you must use a different solution.

The topic should contain:

 <style name="Theme.MyTheme" parent="Theme.Sherlock.ForceOverflow"> <!-- set style for action bar --> <item name="actionBarStyle">@style/Widget.MyTheme.ActionBar</item> <item name="android:actionBarStyle">@style/Widget.MyTheme.ActionBar</item> <!-- set the tab bar style --> <item name="actionBarTabBarStyle">@style/Widget.MyTheme.TabBar</item> <item name="android:actionBarTabBarStyle">@style/Widget.MyTheme.TabBar</item> </style> 

And set the background for the style of the tab bar:

 <style name="Widget.MyTheme.TabBar" parent="Widget.Sherlock.ActionBar.TabBar"> <item name="android:background">#ffff</item> </style> 

Note If you try to combine both approaches, then the background from actionBarTabBarStyle will be placed on top of the background from backgroundStacked .

Note These two approaches set the background for the entire tab bar; the background setting for one tab in the tab bar is different.

Tab text color

If you want to set the text color for tabs, you must define actionBarTabTextStyle .

The topic should contain:

 <style name="Theme.MyTheme" parent="Theme.Sherlock.Light.DarkActionBar"> ... <!-- define text style for tabs --> <item name="actionBarTabTextStyle">@style/MyTheme.ActionBar.TabText</item> <item name="android:actionBarTabTextStyle">@style/MyTheme.ActionBar.TabText</item> </style> 

Tab Text Style:

 <style name="MyTheme.ActionBar.TabText" parent="Widget.Sherlock.ActionBar.TabText" > <item name="android:textColor">#FF000000</item> </style> 
+2
Nov 07 '12 at 13:22
source share



All Articles