android - 如何避免 Material 主题中的强制暗模式?
问题描述
我正在使用 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>
解决方案
更新:一些 OEM 在单个应用程序的基础上提供暗模式功能,这基本上不尊重强制暗模式设置。
在这种情况下,最好忽略与之相关的任何问题。用户会收到有关主题不兼容性的警告,如果不尊重此设置,这至少从他们的角度来看是一件好事。
请不要考虑无法控制的因素,例如覆盖强制暗模式选项(在 Android 10+ 的开发人员选项中提供),这使得选择加入/退出实际上毫无用处。
该功能更多的是反复试验,将浅色元素替换为深色元素(基本但模糊的解释,同意),这可能会影响应用程序的用户体验。
它仅适用于开发人员,而不是作为“用户”功能提供是有原因的。
推荐阅读
- php - PHP OAuth2 这里地图
- reactjs - 如何从笑话中调用 IntersectionObserver 回调函数?
- c# - 当通过 TCP 连接时,Mirth Connect 确实回复/回复
- swift - 如何在 iOS 14、Swift 5 中将状态栏的颜色更改为明暗以外的自定义颜色?
- google-apps-script - 使用脚本复制谷歌工作表,同时保留受保护工作表的权限
- mysql - 将 T-SQL 存储过程查询转换为 MySQL
- php - Fedex 上传文件 API
- javascript - 希望获得有关如何更有效地编写函数的反馈
- c++ - 为什么我需要使用双星号?**
- c++ - 如何在 C++ 中调用类 A 的方法 1 调用类 B 的方法 2?