


I recommend setting it in your application class (if you have one) like so: public class MyApplication extends Application ĭue to what we’ve spoken about above, that will now trigger a recreation in the new version of DayNight. The value you set is not persisted across process starts though, therefore you need to set it every time your app process is started. The method is static so you can call it at any time. Changes between day/night based on the time of day.

If you’re using Material Design Components (and I recommend you to do so), then you can also use the theme from their v1.1.0 release. You need to change your theme to extend from one of the DayNight variants, and then call one method to enable the feature. This has many benefits for your users, from saving power on OLED displays, to increasing usability for people with reduced-vision, and more. The DayNight functionality in AppCompat allows your app to easily switch between a dark ⚫ and light ⚪ theme.
