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

6

最低SDK版本 = 7 目标SDK版本 = 17

如果用户的SDK版本为11或更高版本,则我希望将主题设置为Theme.Holo.Light。但在这里它不起作用。当我在3.1设备上启动应用程序时,它只使用Theme.Light:

enter image description here

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

我的文件夹结构:

enter image description here

清单:

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

values-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>

我应该如何正确使用它?

真诚地 Marco Seiz

2个回答

6
你的styles.xml文件中为什么会有两次主题(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>

请删除您不需要的内容(在本例中为Theme.Light主题):
values-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设备上仍然显示旧主题而不是Holo主题。 - Marco Seiz
你删除了重复吗? - Ahmad
是的,我解决了错误。我不得不为一种语言创建两个文件夹。对于德语:values-de和values-de-v11,英语也是如此...现在它可以工作了 :) 感谢您的帮助和建议! - Marco Seiz

2

请按照@Ahmad提供的方案,在他所说的目录下新建名为themes.xml的文件。

如果您需要使用多语言和多主题,请查看我之前提出的类似问题并得到了回答:

同时使用多语言和多主题


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接