How to use the Holo.Light theme but have the ActionBar use Holo withouth ICS?

Thomas picture Thomas · Jan 9, 2012 · Viewed 42.1k times · Source

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?

Answer

KarlKarlsom picture KarlKarlsom · Jan 9, 2012

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):

<style name="appstyle0" parent="android:style/Theme.Holo.Light">
    <item name="android:actionBarStyle">@android:style/Widget.Holo.ActionBar</item>
</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.

<style name="Widget.Holo.Light.ActionBar" parent="Widget.Holo.ActionBar">
    <item name="android:titleTextStyle">@android:style/TextAppearance.Holo.Widget.ActionBar.Title</item>
    <item name="android:subtitleTextStyle">@android:style/TextAppearance.Holo.Widget.ActionBar.Subtitle</item>
    <item name="android:background">@android:drawable/ab_transparent_light_holo</item>
    <item name="android:backgroundStacked">@android:drawable/ab_stacked_transparent_light_holo</item>
    <item name="android:backgroundSplit">@android:drawable/ab_bottom_transparent_light_holo</item>
    <item name="android:homeAsUpIndicator">@android:drawable/ic_ab_back_holo_light</item>
    <item name="android:progressBarStyle">@android:style/Widget.Holo.Light.ProgressBar.Horizontal</item>
    <item name="android:indeterminateProgressStyle">@android:style/Widget.Holo.Light.ProgressBar</item>
</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:

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

Set this now as.

<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...