Android: How to use different themes for different versions of Android?

MinSDKVersion = 7 TargetSDKVersion = 17

If the user has SDKVersion 11 or higher, I like to ask Theme.Holo.Light theme. This does not work for me. When I run the application on device 3.1, it just uses Theme.Light:

enter image description here

Same thing when I run this application on a device with a lower version than 3.1

My folder:

enter image description here

manifest:

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

v11 values:

 <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> 

folders with other values:

 <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> 

How can I use this correctly?

Regards Marco Seis

+6
source share
2 answers

Why do you have your theme twice in 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> 

Delete the one you don't need (in this case, Theme.Light theme):

v11 values:

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

values:

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

+6
source

Put the solution provided by @Ahmad in new files called themes.xml in the directories he said :-)

If you will be using multilingual and multi-elements, you can take a look at a similar question that I made a few minutes before ... and got the answer:

Multi-language and multi-volume at the same time

+2
source

All Articles