【问题标题】:Android: How to use different themes for different android versions?Android:如何为不同的android版本使用不同的主题?
【发布时间】:2013-01-15 10:15:27
【问题描述】:

MinSDKVersion = 7 TargetSDKVersion = 17

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

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

我的文件夹结构:

清单:

    <application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/MyTheme" >

值-v11:

<resources>

<!--
    Base application theme, dependent on API level. This theme is replaced
    by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="@android:style/Theme.Light">
    <!--
        Theme customizations available in newer API levels can go in
        res/values-vXX/styles.xml, while customizations related to
        backward-compatibility can go here.
    -->
</style>

<!-- Application theme. -->
<style name="AppTheme" parent="@android:style/Theme.Light">
    <!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>


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

其他值文件夹:

<resources>

<!--
    Base application theme, dependent on API level. This theme is replaced
    by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="@android:style/Theme.Light">
    <!--
        Theme customizations available in newer API levels can go in
        res/values-vXX/styles.xml, while customizations related to
        backward-compatibility can go here.
    -->
</style>

<!-- Application theme. -->
<style name="AppTheme" parent="@android:style/Theme.Light">
    <!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>

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

如何正确使用它?

真诚的 马可·塞兹

【问题讨论】:

    标签: android themes manifest


    【解决方案1】:

    为什么你的styles.xml 文件中有两次你的主题?

    <style name="AppTheme" parent="@android:style/Theme.Light">
        <!-- All customizations that are NOT specific to a particular API-level can go here. -->
    </style>
    
    
    <style name="MyTheme" parent="@android:style/Theme.Holo.Light">
        <!-- Any customizations for your app running on devices with Theme.Holo here -->
    </style>
    

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

    值-v11:

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

    价值观:

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

    【讨论】:

    • 我这样做了,但它仍然显示旧主题,而不是我的 android 4.1 和 3.1 设备上的全息主题
    • 您是否删除了重复项?
    • 是的,我做到了。我发现了错误。我必须为一种语言创建两个文件夹。对于德语:values-de AND values-de-v11 和英语相同...现在可以使用 :) 感谢您的帮助和提示!
    【解决方案2】:

    将@Ahmad 提供的解决方案放在他说的目录中名为themes.xml 的新文件中:-)

    如果您将使用多语言和多主题,您可以看看我几分钟前提出的类似问题......并得到了回答:

    Multilanguage and multitheme at same time

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-01
      • 1970-01-01
      • 2013-03-25
      相关资源
      最近更新 更多