【发布时间】:2020-01-23 13:53:42
【问题描述】:
这是我在 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 在 values 中,另一个在 values-night 中。
如果我从手机设置中选择 DarkMode 开启或关闭,它可以工作。 但我想在我的应用程序中有一个 Spinner,有:AUTO、ON、OFF。 如何根据该微调器强制它显示浅色(值)或显示深色(值-夜)?
我尝试在我的 App.kt 类(Application 类)中调用 onCreate() 这个:
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES)
或
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
但是什么也没发生。我做错了什么?
【问题讨论】:
-
stackoverflow.com/a/60149102/11158194 检查这可能对你有帮助。
标签: android view color-scheme android-night-mode android-dark-theme