when using
getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK
to check what mode the app is currently in,
int currentNightMode = getResources().getConfiguration().uiMode
& Configuration.UI_MODE_NIGHT_MASK
switch (currentNightMode) {
case Configuration.UI_MODE_NIGHT_NO:
// Night mode is not active, we're in day time
case Configuration.UI_MODE_NIGHT_YES:
// Night mode is active, we're at night!
case Configuration.UI_MODE_NIGHT_UNDEFINED:
// We don't know what mode we're in, assume notnight
}
if called this with AppCompatDelegate.MODE_NIGHT_YES earlier
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
is the return of currentNightMode to be Configuration.UI_MODE_NIGHT_YES?
what it would return when the AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM was set before
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM);
and the device has changed from light to dark them (or from dark to light)?
tells current what mode the app will be in.
when
if change the system theme in settings (in Android Q), the
configuration.uiModewill reflect the change.same with the
note: the
configuration.uiModechange will trigger a config change and may cause recreate the activity.