How to change Theme dynamically in Android for Different level of API

蹲街弑〆低调 提交于 2020-01-14 06:10:21

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!