Android:如何为不同的Android版本使用不同的主题?

前端之家收集整理的这篇文章主要介绍了Android:如何为不同的Android版本使用不同的主题?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
MinSDKVersion = 7
TargetSDKVersion = 17

如果用户拥有SDKVersion 11或更高版本,我想将主题设置为Theme.Holo.Light.
它在这里对我不起作用.当我在3.1设备上启动应用程序时,它只使用Theme.Light:

当我在版本低于3.1的设备上运行此应用程序时也是如此

我的文件夹结构:

表现:

  1. <application
  2. android:allowBackup="true"
  3. android:icon="@drawable/ic_launcher"
  4. android:label="@string/app_name"
  5. android:theme="@style/MyTheme" >

值-V11:

  1. <resources>
  2.  
  3. <!--
  4. Base application theme,dependent on API level. This theme is replaced
  5. by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
  6. -->
  7. <style name="AppBaseTheme" parent="@android:style/Theme.Light">
  8. <!--
  9. Theme customizations available in newer API levels can go in
  10. res/values-vXX/styles.xml,while customizations related to
  11. backward-compatibility can go here.
  12. -->
  13. </style>
  14.  
  15. <!-- Application theme. -->
  16. <style name="AppTheme" parent="@android:style/Theme.Light">
  17. <!-- All customizations that are NOT specific to a particular API-level can go here. -->
  18. </style>
  19.  
  20.  
  21. <style name="MyTheme" parent="@android:style/Theme.Holo.Light">
  22. <!-- Any customizations for your app running on devices with Theme.Holo here -->
  23. </style>

其他值文件夹:

  1. <resources>
  2.  
  3. <!--
  4. Base application theme,while customizations related to
  5. backward-compatibility can go here.
  6. -->
  7. </style>
  8.  
  9. <!-- Application theme. -->
  10. <style name="AppTheme" parent="@android:style/Theme.Light">
  11. <!-- All customizations that are NOT specific to a particular API-level can go here. -->
  12. </style>
  13.  
  14. <style name="MyTheme" parent="@android:style/Theme.Light">
  15. <!-- Any customizations for your app running on devices with Theme.Holo here -->
  16. </style>

我怎样才能正确使用它?

诚挚
Marco Seiz

解决方法

为什么在styles.xml文件中有两次主题
  1. <style name="AppTheme" parent="@android:style/Theme.Light">
  2. <!-- All customizations that are NOT specific to a particular API-level can go here. -->
  3. </style>
  4.  
  5.  
  6. <style name="MyTheme" parent="@android:style/Theme.Holo.Light">
  7. <!-- Any customizations for your app running on devices with Theme.Holo here -->
  8. </style>

删除不需要的那个(在本例中为Theme.Light主题):

值-V11:

  1. <style name="MyTheme" parent="@android:style/Theme.Holo.Light">
  2. <!-- Any customizations for your app running on devices with Theme.Holo here -->
  3. </style>

值:

  1. <style name="MyTheme" parent="@android:style/Theme.Light">
  2. <!-- Any customizations for your app running on devices with Theme.Holo here -->
  3. </style>

猜你在找的Android相关文章