带有configChanges的Android DayNight主题

问题描述 投票:1回答:2

我正在创建一个应用程序,我使用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停止工作,并在每次轮换中重新创建de活动。

欢迎任何形式的帮助

android rotation orientation
2个回答
1
投票

您可能需要在清单中添加“uiMode”参数:

android:configChanges="orientation|screenSize|uiMode|keyboardHidden"

0
投票

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

直到它固定我会添加uiMode标志到android:configChanges像提到here

© www.soinside.com 2019 - 2024. All rights reserved.