22

I am preparing my app to work smoothly with honeycomb. I have an small aesthetics question regarding with the android theme.

For honeycomb it is recommended that the following theme is used.

android:theme="@android:style/Theme.Holo.Light" 

How can I make my app use another theme when it is used in a previous version?

Thanks in advance

Programmer Bruce
  • 64,977
  • 7
  • 99
  • 97
biquillo
  • 6,469
  • 7
  • 37
  • 40

1 Answers1

33

EDIT: Updated for released version of the 3.0 SDK.


One way to do this is to set <uses-sdk android:targetSdkVersion="11">. You should also place this above your <application> definition. This will tell the system to use the Holographic theme if it's available, and the default theme otherwise.

Another way to do this, is to define a theme, say MyTheme, that inherits from a different theme depending on the API level / OS version. You can do this using resource directory qualifiers.

Your directory structure could look like this:

res/
  values/
    styles.xml
  values-v11/
    styles.xml

The contents of res/values/styles.xml would be something like:

<resources>
  <style name="MyTheme" parent="@android:style/Theme.Light">
    ...
  </style>
</resources>

And the contents of res/values-v11/styles.xml would be something like:

<resources>
  <style name="MyTheme" parent="@android:style/Theme.Holo.Light">
    ...
  </style>
</resources>

Note that in the future, the Holo theme may not always make sense by API level, so you may need to tweak this approach later on. You can also use other directory qualifiers such as values-large-v11 or the like. It's entirely up to you.

Roman Nurik
  • 29,665
  • 7
  • 84
  • 82
  • Awesome, thanks Roman. I'm curious what you mean by "Note that in the future, the Holo theme may not always make sense by API level". Do you mean to say that the Holo theme may be different or a whole new theme added in future releases? Thus the developer might need to accommodate more themes? This makes it difficult to simply do something such as use the default theme (whether it be Theme or Theme.Holo) with NoTitleBar. Anyway, thanks for any clarification; I'm looking forward to ICS – Tony Chan Nov 28 '11 at 22:41
  • That was a fairly short-sighted comment :-) Striking it out now. Holo definitely makes sense for API 11+, regardless of physical size. – Roman Nurik Nov 28 '11 at 22:58
  • @RomanNurik - I don't get auto-complete to recognize Holo Light, even when the target is 11. Only after changing in project.properties the target to android-11, was the project been able to compile and the auto-complete worked. – AlikElzin-kilaka Nov 15 '12 at 14:30
  • The downside now is that I can mistakenly use high level API and crash the app on older devices, because my minSdkVersion is set to 8. – AlikElzin-kilaka Nov 15 '12 at 14:34
  • @kilaka the Android Lint tool can help you watch out for things like that. – Roman Nurik Nov 15 '12 at 16:19
  • I know and hate patching things for several versions. Lint's apicheck is a patching tool. Anyhow, after trying the new holo light theme, some of my dialogs looked too bright. Now I need to patch things up for holo. Bitching... Thanks for the help. – AlikElzin-kilaka Nov 15 '12 at 20:28
  • On SDK level 14, would the phone use the 11 theme or the default? – AgentKnopf Mar 15 '13 at 06:36
  • @Zainodis the device would use the API 11 theme; `-v11` means *at least API 11*. – Roman Nurik Mar 15 '13 at 11:41