Change theme according to android version

不想你离开。 提交于 2019-11-28 04:24:34

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!