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

标签 android themes manifest

MinSDKVersion = 7 TargetSDKVersion = 17

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

enter image description here

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

我的文件夹结构:

enter image description here

list :

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

如何正确使用它?

真诚的 马尔科塞兹

最佳答案

为什么您的主题在 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>

值(value)观:

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

关于Android:如何为不同的android版本使用不同的主题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14335453/

相关文章:

themes - 根据安装的 Domino 版本使用 OneUI 主题

powershell - 如何使用模块 list 导出 PowerShell 模块别名?

android - [Google Drive Android SDK]上传文件成功或失败如何通知?

android - 将relativelayout的宽度设置为屏幕宽度的1/3?

android - Eclipse Android 项目已创建且始终缺少 R 元素

cordova - 将 privateNetworkClientServer 功能添加到 Windows 8 Cordova 应用程序

xml - 此应用程序启动失败,因为应用程序配置不正确(VS 2010中的VS 2017)

android - mediaRecorder 记录最后 X 秒

android - 应用程序没有指定主题时会发生什么

android - 无法应用新的 Android 布局