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 主题


- 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01
- 想使用ViewPager,无法识别android.support.*? 2022-01-01
- Android - 拆分 Drawable 2022-01-01
- 用 Swift 实现 UITextFieldDelegate 2022-01-01
- 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01
- android 4中的android RadioButton问题 2022-01-01
- Android viewpager检测滑动超出范围 2022-01-01
- MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01
- Android - 我如何找出用户有多少未读电子邮件? 2022-01-01
- 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01