1

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

在 SO 上看到了这篇文章,不幸的是它对我不起作用。

那么,如何解决这个问题呢?

样式.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>
4

1 回答 1

1

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

在这种情况下,最好忽略与之相关的任何问题。用户会收到有关主题不兼容性的警告,如果不尊重此设置,这至少从他们的角度来看是一件好事。


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

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

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

于 2020-10-19T18:56:57.117 回答