Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 620
Thomas Avatar asked Jan 09 '12 17:01

Thomas


People also ask

How to set Holo light theme in android?

To use a Holo theme, explicitly request one from your manifest on your activity or application element, e.g. android:theme="@android:style/Theme. Holo" . Your app will be displayed using the unmodified theme on all compatible Android 4.0 devices.

What is Holo android?

Holo, or Holo theme, is a standard theme for Android apps that Google first introduced with Android 3.0 Honeycomb. The company requires manufacturers to include the unmodified Holo theme in Android 4.0 or higher devices if they want to integrate Android Market on their device.


2 Answers

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

like image 200
KarlKarlsom Avatar answered Sep 19 '22 15:09

KarlKarlsom


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.

like image 42
kristesla Avatar answered Sep 16 '22 15:09

kristesla