Night Mode



To set the DayNight theme in our application we use the method: AppCompatDelegate.setDefaultNightMode() Following are the arguments allowed in the above method.

  • MODE_NIGHT_YES – Enables night mode manually.
  • MODE_NIGHT_NO – Disables night mode manually.
  • MODE_NIGHT_FOLLOW_SYSTEM – Uses the system settings to determine the time of day and toggles NightMode accordingly. This is the default argument.
  • MODE_NIGHT_AUTO – This tries to auto-detect the time from the device location APIs. If the runtime permission for location services isn’t granted, then it uses the system time.

Add the following code in the onCreate() method.



Comments