开发者

Change theme according to android version

开发者 https://www.devze.com 2023-02-07 18:44 出处:网络
I am preparing my app to work smoothly with honeycomb. I have an small aesthetics question regar开发者_如何学运维ding with the android theme.

I am preparing my app to work smoothly with honeycomb. I have an small aesthetics question regar开发者_如何学运维ding 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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消