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

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

问题描述

在应用程序中,我设置了 android:minSdkVersion =8 android:targetSdkVersion =19现在我想根据android版本改变应用程序的主题。如果api级别为8,则 Datepicker 应该出现

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 Datepicker 应该出现

And if the level is above 11 Datepicker should appear

推荐答案

尝试这个花花公子:)

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

res / values / 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 / values-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天全站免登陆