0

这是我在 attr_styles.xml 中的风格

<style name="AttrStyles" parent="Theme.AppCompat.DayNight.NoActionBar">
    <item name="calendarAppointmentView">@style/calendar_appointment_view</item>
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
    <item name="alertDialogTheme">@style/white_style</item>
</style>

我有 2 个 colors.xml 文件。1 在值中,另一个在值中。

如果我从手机设置中选择 DarkMode 打开或关闭,它可以工作。但我想在我的应用程序中有一个 Spinner,有:AUTO、ON、OFF。如何根据该微调器强制它显示浅色(值)或显示深色(值-夜)?

我尝试在我的 App.kt 类(Application 类)中调用 onCreate() 这个:

    AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES)

或者

    AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)

但什么也没有发生。我究竟做错了什么?

4

1 回答 1

0

在搜索您的问题大约 2 分钟后,我遇到了一个类似的问题,该问题几乎有您正在寻找的答案。看来您必须使用方法 setTheme。

于 2020-01-23T14:03:34.077 回答