You can use the night resource qualifier folder.
In this way you can define colors and the other resources for the dark (night) and for the light theme (day).
Qualifiers:
night
: Night time
notnight
: Day time
In order to support the dark theme with a Material Components Theme use:
<style name="Theme.MyApp" parent="Theme.MaterialComponents.DayNight">
<!-- ... -->
</style>
With an AppCompat theme:
<style name="AppTheme" parent="Theme.AppCompat.DayNight">
<item name="colorPrimary">@color/primary</item>
</style>
Then define in your app theme the references color resources, and override the value in the values-night
directory if needed:
Example: resvaluescolors.xml
:
<color name="colorPrimary">.....</color>
In resvalues-nightcolors.xml
folders define the same color:
<color name="colorPrimary">.....</color>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…