Appcompat Mode_night_auto Not Working
AppCompatDelegate.MODE_NIGHT_AUTO is not updating my existing activity and I'm not sure why. I dynamically allow the user to change night mode. If the user changes the mode to auto
Solution 1:
In case anyone else wants to know what I did to solve this (not sure if it is the right way to do it though):
private int mCurrentNightMode;
@OverrideprotectedvoidonCreate(Bundle savedInstanceState) {
mCurrentNightMode = getCurrentNightMode();
}
@OverrideprotectedvoidonPostResume() {
super.onPostResume();
if (hasNightModeChanged()) {
delayedRecreate();
}
}
privatevoiddelayedRecreate() {
Handler handler = newHandler();
handler.postDelayed(this::recreate, 1);
}
privatebooleanhasNightModeChanged() {
getDelegate().applyDayNight();
return mCurrentNightMode != getCurrentNightMode();
}
private int getCurrentNightMode() {
returngetResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;
}
Solution 2:
It's been fixed in AppCompat 24.2.0. Revision history lists this as a "behaviour change" for 24.2.0:
If you use the appcompat library's day/night functionality, the system now automatically recreates your activity whenever the day/night mode changes (either because of the time of day, or because of a call to AppCompatDelegate.setLocalNightMode()).
Post a Comment for "Appcompat Mode_night_auto Not Working"