可能你需要一个文件夹——[values-night]。
在您的 theme.xml(或 style.xml)中,您可以设置日主题,如:
<style name="Theme.MyTheme" parent="Theme.MaterialComponents.DayNight.NoActionBar" >
<item name="minor customization">@style/ThemeOverlay.MyTheme.DayCustom</item>
</style>
在你的 theme-night.xml(或 style-night.xml)中:
<style name="Theme.MyTheme" parent="Theme.MaterialComponents.DayNight.NoActionBar" >
<item name="minor customization">@style/ThemeOverlay.MyTheme.NightCustom</item>
</style>
在风格上,你应该初始化这些:
<style name="ThemeOverlay.MyTheme.NightCustom" parent="">
<item name="colorPrimary">@color/nightLime1</item>
<item name="colorPrimaryDark">@color/nightLime2</item>
<item name="colorControlHighlight">@color/nightLime3</item>
</style>
<style name="ThemeOverlay.MyTheme.DayCustom" parent="">
<item name="colorPrimary">@color/dayLime1</item>
<item name="colorPrimaryDark">@color/dayLime2</item>
<item name="colorControlHighlight">@color/dayLime3</item>
</style>
关键在ThemeOverlay中,ThemeOverlay.MyTheme.DayCustom 或 ThemeOverlay.MyTheme.NightCustom 的父级为“”,因为系统会自动识别为 ThemeOverlay,只需更改您设置的样式,如 colorPrimary,colorPrimaryDark...