如何动态地更改主题在Android中为不同级别的API的 [英] How to change Theme dynamically in Android for Different level of API

查看:111
本文介绍了如何动态地更改主题在Android中为不同级别的API的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在应用程序,我已经设置了安卓的minSdkVersion =8的android:targetSdkVersion =19现在我想改变这取决于Android版应用程序的主题。一样,如果API级别是8本日期选择器应该出现

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

而如果水平高于11 日期选择器应该出现

And if the level is above 11 Datepicker should appear

推荐答案

试着用这家伙:)

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

RES /价值/ styles.xml的内容会是这样的:

The contents of res/values/styles.xml would be something like:

<resources>
  <style name="MyTheme" parent="@android:style/Theme.Light">
    ...
  </style>
</resources>

和RES /值-V11的内容/ styles.xml会是这样的:

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>

这篇关于如何动态地更改主题在Android中为不同级别的API的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆