如何在Material主题中避免强制暗模式?

时间:2020-10-17 14:46:51

标签: android android-layout material-components-android android-darkmode

我正在使用Material主题。我希望我的应用仅以浅色为主题(目前,我们没有针对深色模式的任何计划)。一些设备在应用程序上强制使用暗模式,我想避免这种情况。

我见过this post on SO,很遗憾,它对我不起作用。

那么,如何解决呢?

Styles.xml

   <resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
        <item name="materialButtonStyle">@style/ButtonTheme</item>
    </style>

    <style name="LandingTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/White</item>
        <item name="colorAccent">@color/colorAccent</item>
        <item name="android:buttonStyle">@style/ButtonTheme</item>
    </style>
</resoures>

1 个答案:

答案 0 :(得分:1)

更新:某些OEM在单个应用的基础上提供了暗模式功能,该功能基本上不遵守强制暗模式设置。

在这种情况下,最好忽略与其有关的任何问题。警告用户主题不兼容,如果不遵守此设置,至少从他们的角度来说这是一件好事。


请不要考虑不可控制的因素,例如 overrideing 强制黑暗模式选项(可从Android 10+的Developer Options中获得),这使得选择加入/退出实际上无效了< / strong>。

此功能更多是反复试验,将深色元素替换为深色元素(基本但含糊的解释,已达成共识),这可能破坏或破坏应用程序的用户体验。

有一个原因为什么它仅适用于开发人员,而不能作为“用户”功能使用。