问题
in application i have set the android:minSdkVersion="8" and android:targetSdkVersion="19" now i want to change the theme of the application depending upon the android version. like if api level is 8 this Datepicker should appear
And if the level is above 11 Datepicker should appear
回答1:
try with this dude :)
int currentapiVersion = android.os.Build.VERSION.SDK_INT;
System.out.println("mdpi current version is =="+ currentapiVersion);
if ( currentapiVersion < 11)
{
// your condition code for date picker
}
else
{
// your condition code for date picker
}
Your directory structure could look like this:
res/
values/
styles.xml
values-v11/
styles.xml
The contents of res/values/styles.xml would be something like:
<resources>
<style name="MyTheme" parent="@android:style/Theme.Light">
...
</style>
</resources>
And the contents of res/values-v11/styles.xml would be something like:
<resources>
<style name="MyTheme" parent="@android:style/Theme.Holo.Light">
...
</style>
</resources>
回答2:
Create your own theme, and make it extend a different theme depending on API level, for example if you put the theme in the folder values-v11 it will will work for api level 11 and above. I hope I made myself clear
回答3:
Use different values folder according to your api need. Use values-v11 folder to change theme above api level 11 like this :
<style name="AppBaseTheme" parent="android:Theme.Holo">
<!-- API 11 theme customizations can go here. -->
</style>
Place this style.xml in values-v11 folder.
来源:https://stackoverflow.com/questions/22828781/how-to-change-theme-dynamically-in-android-for-different-level-of-api