Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change theme according to android version

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

like image 704
biquillo Avatar asked Feb 01 '11 17:02

biquillo


1 Answers

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.

like image 64
Roman Nurik Avatar answered Nov 19 '22 08:11

Roman Nurik