Different Theme for different Android SDK versions

你说的曾经没有我的故事 提交于 2019-11-27 20:29:25

问题


Is there a way to use a different theme depending on which SDK version the application is installed on?

The reason I ask is because I want to support all the way back to SDK version 8, but for those users that have ICS I want to be able to follow the design standards for ICS and use the Holo theme.

I can see from Program different layouts for different versions in android that I can have a folder values-v14 which will have a theme.xml to override the theme declaration. However, it won't compile if I reference Theme.Holo. I believe this is because I have the following in my AndroidManifest.xml

<uses-sdk android:minSdkVersion="8" />
<uses-sdk android:targetSdkVersion="11"/>

Any pointers would be much appreciated.

UPDATE:- OK so here are my files:- AndroidManifest.xml:

<application
    android:icon="@drawable/icon"
    android:label="@string/app_name"
    android:name=".Refunder"
    android:theme="@style/MainTheme"
    >

res/values/themes.xml:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="MainTheme" parent="@android:style/Theme.Light.NoTitleBar">
        <item name="android:typeface">normal</item>
        <item name="android:textSize">15sp</item>
    </style>
</resources>

res/values-v11/themes.xml:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="MainTheme" parent="@android:style/Theme.Holo">
        <item name="android:typeface">normal</item>
        <item name="android:textSize">15sp</item>
    </style>
</resources>

This is in accordance with the article I read here:- http://android-developers.blogspot.com/2012/01/holo-everywhere.html

When I do this I get a compile error in Eclipse saying that:-

error: Error retrieving parent for item: No resource found that matches the given name '@android:style/Theme.Holo'

回答1:


What you are doing (with your values-v14 folder) is correct. You just need to change your Build Target to allow it to compile. (right click your project, choose properties, select Android, Choose Android 14 or above)

Make sure you do not use any features greater than your android:minSdkVersion as it will cause a Force Close if used on an earlier version of Android.



来源:https://stackoverflow.com/questions/9140085/different-theme-for-different-android-sdk-versions

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