【问题标题】:How to avoid forced dark mode in Material theme?如何避免 Material 主题中的强制暗模式?
【发布时间】:2020-10-17 14:46:51
【问题描述】:

我正在使用 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>

【问题讨论】:

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


    【解决方案1】:

    更新:一些 OEM 在单个应用程序的基础上提供暗模式功能,这基本上不尊重强制暗模式设置。

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


    请不要考虑无法控制的因素,例如覆盖强制暗模式选项(在 Android 10+ 的开发人员选项中提供),这使得选择加入/退出实际上毫无用处。

    该功能更多的是反复试验,将浅色元素替换为深色元素(基本但模糊的解释,同意),这可能会影响应用程序的用户体验。

    它仅适用于开发人员,而不是作为“用户”功能提供是有原因的。

    【讨论】:

    • 其实我不是在寻找那个(覆盖开发人员选项的强制暗模式选项)。我正在寻找覆盖设置上的暗模式(默认不是开发人员选项)
    • 我不认为在系统中启用暗模式会“强制”应用程序变暗。事实上,开发者必须实现 DayNight 主题才能遵循系统的暗模式设置 - source
    • 非常感谢您的链接!在我的特殊情况下,在我的小米手机上启用暗模式会导致应用程序处于暗模式。可能是 OEM 问题?
    • 啊,这个MIUI功能好像不尊重设置。好吧,这就是你的 OEM 积极性。
    • 您可以放心地忽略这一点,因为对此无能为力。这是刚从开发者选项中退出的“强制黑暗模式”。
    猜你喜欢
    • 2022-11-24
    • 1970-01-01
    • 2020-01-26
    • 2021-10-24
    • 2020-02-12
    • 1970-01-01
    • 2021-05-11
    • 2020-12-11
    相关资源
    最近更新 更多