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'
A style is a collection of attributes that specify the appearance for a single View . A style can specify attributes such as font color, font size, background color, and much more. A theme is a collection of attributes that's applied to an entire app, activity, or view hierarchy—not just an individual view.
In Android Studio, open themes. xml (app > res > values > themes > themes.
Go to File > Settings, now under IDE settings click on appearance and select the theme of your choice from the dropdown. File > Import Settings , select the file or your choice and select ok a pop up to restart the studio will open up click yes and studio will restart and your theme will be applied.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With