Android DayNight Theme with configChanges(带有 configChanges 的 Android DayNight 主题)
问题描述
我正在创建一个应用,其中使用 Android 支持库的主题 DayNight.
I'm creating an app where I use the theme DayNight of the Android support libraries.
这是themes.xml中的代码
This is the code in themes.xml
<style name="ActivityTheme" parent="Theme.AppCompat.DayNight.NoActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
我在清单中使用 configChanges 来管理轮换.
I use configChanges in the manifest to manage rotations.
android:configChanges="keyboardHidden|orientation|screenSize"
在我的 AppcompatActivity 的 onCreate 中,我添加了:
In the onCreate on my AppcompatActivity I have added:
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES)
问题是当我使用 setDefaultNightMode 时,android:configChanges 停止工作,并在每次轮换中重新创建活动.
The problem is that when I use setDefaultNightMode, android:configChanges stops working, and recreate de activity in every rotation.
欢迎任何形式的帮助
推荐答案
好像是个bug,会根据这个在AppCompat v.1.1.0中修复问题.
Seems to be a bug and will be fixed in AppCompat v.1.1.0 according to this issue.
在其修复之前,我会将 uiMode
标志添加到 android:configChanges
中,就像提到的 这里
Until its fixed I would add the uiMode
flag to android:configChanges
like mentioned here
这篇关于带有 configChanges 的 Android DayNight 主题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:带有 configChanges 的 Android DayNight 主题


基础教程推荐
- 如何从 logcat 中删除旧数据? 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01