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

42,235

Solution 1

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

Solution 2

I ran into a similar problem when I wanted to put a custom view in the actionbar. I wanted a dark action bar while the rest of the app remained light. More specifically I had spinners in the action bar.

First your theme should extend

<style name="MyTheme.Light" parent="android:Theme.Holo.Light.DarkActionBar">

Next, from your activity, use getActionBar().getThemedContext() as the context for inflating your views. In my instance, it's what I passed to my spinner array adapters.

Worked perfectly for me.

Share:
42,235
Thomas
Author by

Thomas

Updated on March 13, 2020

Comments

  • Thomas
    Thomas about 4 years

    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?

  • Thomas
    Thomas over 12 years
    Doesn't work for me. For example: <style name="video2brainTheme" parent="@android:style/Theme.Holo.Light"> <item name="android:windowBackground">@color/background_color</ite‌​m> <item name="android:actionBarStyle">@style/CustomActionBarStyle</i‌​tem> </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.
  • Taranfx
    Taranfx about 12 years
    The mentioned drawables are not public, how doe sit work for you?