如何动态地更改主题在Android中为不同级别的API的别的、中为、动态、主题

2023-09-07 09:55:47 作者:出租半张床

在应用程序,我已经设置了安卓的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>