2013-01-15 56 views
6

的minSdkVersion = 7 TargetSDKVersion = 17Android:如何针对不同的Android版本使用不同的主题?

如果用户具有SDKVersion 11或更高我喜欢设置主题Theme.Holo.Light。 它在这里不适用于我。当我启动了3.1设备上的应用程序,它只是使用了Theme.Light:

enter image description here

同样的,当我在设备上运行此应用程式版本低于3.1

我Folderstructure:

enter image description here

清单:

<application 
    android:allowBackup="true" 
    android:icon="@drawable/ic_launcher" 
    android:label="@string/app_name" 
    android:theme="@style/MyTheme" > 

值-V11:

<resources> 

<!-- 
    Base application theme, dependent on API level. This theme is replaced 
    by AppBaseTheme from res/values-vXX/styles.xml on newer devices. 
--> 
<style name="AppBaseTheme" parent="@android:style/Theme.Light"> 
    <!-- 
     Theme customizations available in newer API levels can go in 
     res/values-vXX/styles.xml, while customizations related to 
     backward-compatibility can go here. 
    --> 
</style> 

<!-- Application theme. --> 
<style name="AppTheme" parent="@android:style/Theme.Light"> 
    <!-- All customizations that are NOT specific to a particular API-level can go here. --> 
</style> 


<style name="MyTheme" parent="@android:style/Theme.Holo.Light"> 
    <!-- Any customizations for your app running on devices with Theme.Holo here --> 
</style> 

其它数值的文件夹:

<resources> 

<!-- 
    Base application theme, dependent on API level. This theme is replaced 
    by AppBaseTheme from res/values-vXX/styles.xml on newer devices. 
--> 
<style name="AppBaseTheme" parent="@android:style/Theme.Light"> 
    <!-- 
     Theme customizations available in newer API levels can go in 
     res/values-vXX/styles.xml, while customizations related to 
     backward-compatibility can go here. 
    --> 
</style> 

<!-- Application theme. --> 
<style name="AppTheme" parent="@android:style/Theme.Light"> 
    <!-- All customizations that are NOT specific to a particular API-level can go here. --> 
</style> 

    <style name="MyTheme" parent="@android:style/Theme.Light"> 
    <!-- Any customizations for your app running on devices with Theme.Holo here --> 
</style> 

我该如何正确使用它?

真诚 马尔科Seiz

回答

6

为什么你有你的主题两次在styles.xml文件?

<style name="AppTheme" parent="@android:style/Theme.Light"> 
    <!-- All customizations that are NOT specific to a particular API-level can go here. --> 
</style> 


<style name="MyTheme" parent="@android:style/Theme.Holo.Light"> 
    <!-- Any customizations for your app running on devices with Theme.Holo here --> 
</style> 

删除你不需要(在这种情况下,Theme.Light主题)的一个:

值-V11:

<style name="MyTheme" parent="@android:style/Theme.Holo.Light"> 
    <!-- Any customizations for your app running on devices with Theme.Holo here --> 
</style> 

值:

<style name="MyTheme" parent="@android:style/Theme.Light"> 
    <!-- Any customizations for your app running on devices with Theme.Holo here --> 
</style> 

+0

我这样做,但它仍然显示旧的主题,而不是我的Android 4.1和3.1设备 –

+0

上的全息主题你删除重复? – Ahmad

+0

是的,我做到了。我找出了错误。我必须为一种语言创建两个文件夹。对于德语:values-de和values-de-v11和英语相同......现在可以运行:)感谢您的帮助和提示! –

2

将通过@Ahmad在新文件中提供的解决方案称为的themes.xml对他说:-)

如果你使用多语言和multithemes,你可以看看类似的问题在我的目录做了一些分钟,然后...并得到了回答:

Multilanguage and multitheme at same time

相关问题