2013-01-15 90 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

相關問題