如何避免 Material 主题中的强制暗模式?
How to avoid forced dark mode in Material theme?
我正在使用 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>
更新:一些 OEM 在 individual-app 基础上提供 dark-mode 功能 ,这基本上不符合 forced-dark 模式设置.
在那种情况下,最好忽略与之相关的任何问题。用户会收到关于主题不兼容的警告,如果不遵守此设置,这至少对他们来说是一件好事。
请不要考虑无法控制的因素,例如 覆盖 强制黑暗模式选项(在 Android 10+ 的开发人员选项中可用),这使得 opt-in/out 实际上没用 .
该功能更像是一个 trial-and-error,将浅色元素替换为深色元素(基本但模糊的解释,同意),这可能 make-or-break 应用程序的用户体验。
它仅供开发人员使用,而不作为“用户”功能提供是有原因的。
我正在使用 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>
更新:一些 OEM 在 individual-app 基础上提供 dark-mode 功能 ,这基本上不符合 forced-dark 模式设置.
在那种情况下,最好忽略与之相关的任何问题。用户会收到关于主题不兼容的警告,如果不遵守此设置,这至少对他们来说是一件好事。
请不要考虑无法控制的因素,例如 覆盖 强制黑暗模式选项(在 Android 10+ 的开发人员选项中可用),这使得 opt-in/out 实际上没用 .
该功能更像是一个 trial-and-error,将浅色元素替换为深色元素(基本但模糊的解释,同意),这可能 make-or-break 应用程序的用户体验。
它仅供开发人员使用,而不作为“用户”功能提供是有原因的。