首页 > 解决方案 > 带有 configChanges 的 Android DayNight 主题

问题描述

我正在创建一个应用程序,在其中使用 Android 支持库的主题 DayNight。

这是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 来管理轮换。

android:configChanges="keyboardHidden|orientation|screenSize"

在我的 AppcompatActivity 的 onCreate 中,我添加了:

AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES)

问题是当我使用 setDefaultNightMode 时,android:configChanges 停止工作,并在每次轮换中重新创建活动。

欢迎任何形式的帮助

标签: androidrotationorientation

解决方案


似乎是一个错误,将根据此问题在 AppCompat v.1.1.0 中修复。

在它修复之前,我会将uiMode标志添加到这里android:configChanges提到的


推荐阅读