Chrisの梳羽之礁

A look of quick intelligence and soft refinement
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

原文:http://stackoverflow.com/questions/8792517/how-to-use-the-holo-light-theme-but-have-the-actionbar-use-holo-withouth-ics

I would like to have a dark ActionBar but have the rest of the application use the Holo.Light theme. I know there is a Theme.Holo.Light.DarkActionBar Theme in ICS/4.0 but I want this also to work in Honeycomb/3.0+.

At the Moment I'm using the dark Holo theme and for the rest of my components I'm using a ContextThemeWrapper. But this is much work and can easily lead to errors.

Is this possible?

 

 

Create a custom style and set the Parent style to the holo light theme but the ActionBar to normal Holo.

a xml file with something like this should do the job (just out of my memory):

1 <style name="appstyle0"parent="android:style/Theme.Holo.Light"> 
2     <item name="android:actionBarStyle">@android:style/Widget.Holo.ActionBar</item> 
3 </style> 

 

Then set the appstyle0 in your AndroidManifest.xml as style and in all your Activitys are holo light theme but the action bar style is holo dark.

Edit: I checked why my first answer does not work.

 1 <style name="Widget.Holo.Light.ActionBar"parent="Widget.Holo.ActionBar"> 
 2     <item name="android:titleTextStyle">@android:style/TextAppearance.Holo.Widget.ActionBar.Title</item> 
 3     <item name="android:subtitleTextStyle">@android:style/TextAppearance.Holo.Widget.ActionBar.Subtitle</item> 
 4     <item name="android:background">@android:drawable/ab_transparent_light_holo</item> 
 5     <item name="android:backgroundStacked">@android:drawable/ab_stacked_transparent_light_holo</item> 
 6     <item name="android:backgroundSplit">@android:drawable/ab_bottom_transparent_light_holo</item> 
 7     <item name="android:homeAsUpIndicator">@android:drawable/ic_ab_back_holo_light</item> 
 8     <item name="android:progressBarStyle">@android:style/Widget.Holo.Light.ProgressBar.Horizontal</item> 
 9     <item name="android:indeterminateProgressStyle">@android:style/Widget.Holo.Light.ProgressBar</item> 
10 </style> 

 

The action bar is defined in styles.xml with attributes that are set by the main theme in general. First of all the BG is transparent, so you should use "Widget.Holo.Light.ActionBar.Solid" as parent. Then you have to set the different items one by one to the dark theme. Lets take titleTextStyle as example:

1 <style name="TextAppearance.Holo.Widget.ActionBar.Title.Own" 
2        parent="TextAppearance.Holo.Widget.ActionBar.Title"> 
3     <item name="android:textColor">@android:color/primary_text_holo_dark</item> 
4     <item name="android:textColorHighlight">@android:color/highlighted_text_holo_dark</item> 
5     <item name="android:textColorHint">@android:color/hint_foreground_holo_dark</item> 
6     <item name="android:textColorLink">@android:color/holo_blue_light</item> 
7 </style> 

 

Set this now as.

1 <item name="android:titleTextStyle">@android:style/TextAppearance.Holo.Widget.ActionBar.Title.Own</item> 

 

Proceed like this with the xml attributes above.

To find all related attributes search in styles.xml and themes.xml for the parameters. Sorry to tell, but I guess there is no easy way, according to what I see...

 

 

 

Doesn't work for me. For example: <style name="video2brainTheme" parent="@android:style/Theme.Holo.Light"> <item name="android:windowBackground">@color/background_color</item> <item name="android:actionBarStyle">@style/CustomActionBarStyle</item> </style> <style name="CustomActionBarStyle" parent="android:Widget.Holo.ActionBar"> <item name="android:paddingLeft">32dp</item> </style> This gives me the paddingLeft but does not apply the dark Holo Theme to the actionbar - it's still the light theme. – Thomas Jan 10 at 8:38
Sorry to tell, its not so easy. I updated the answer. – KarlKarlsom Jan 10 at 15:39
Thx - I will try this. – Thomas Jan 13 at 13:58
The mentioned drawables are not public, how doe sit work for you? – geeknizer Mar 5 at 11:33