android - 如何根据设备的暗模式选择设置主题?
问题描述
我在styles.xml 中设置了两个主题。当应用程序启动时,我想根据设备的暗模式选择设置适当的主题。假设我想在暗/亮模式下为 windowBackground 设置不同的颜色。
(初始窗口背景颜色是在 React 加载之前设置的,所以应该在 Android 端完成。)
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowBackground">#ff0000</item>
</style>
<style name="AppTheme.Dark" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowBackground">#00ff00</item>
</style>
</resources>
解决方案
只需在 android/app/src/main/res/ 创建一个 values-night 文件夹并在其中放置另一个带有深色主题的 styles.xml 即可解决我的问题。
<resources>
<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowBackground">#00ff00</item>
</style>
</resources>
推荐阅读
- ios - 选择颜色更改 FSCalendar 中的事件颜色
- java - Java中的多核编程
- perl - 如何在 IIS 10 中配置 perl 文件?
- perl - perl - 无法使用 m//g 字符串获取数据
- html - TinyMCE 编辑器高度不会改变
- python - 如何为 avro 联合类型指定数据而没有歧义?
- javascript - 拆分器上的 KendoUI 附加窗格
- javascript - ui路由器中的Angular Provider访问
- vulkan - 如何正确共享 VkDeviceMemory?VkExternalMemoryBufferCreateInfoKHR 有什么用?
- javascript - 阻止执行特定的内联脚本标签