I'm trying to implement dark mode for my app. every thing is fine so far, user have option to turn On/Off dark mode from app settings.
But when the system is in dark mode and dark mode from app setting is turned off there is color mixing happening like some colors loads from night resources and some other from light resources.
knowing that this problem happens only for some devices like Xiaomi note 9.
what I'm doing: on Application class on create first checks system dark mode if user didn't change from app settings, then filling the value in app settings based on system, after that if user launch application again then I'm loading the value from shared preferences
@Override
public void onCreate() {
PreferencesUtils preferencesUtils = new PreferencesUtils(this);
if (preferencesUtils.isDarkModeCheck() == null) { // on first install user didn't edit configuration
int nightModeFlags =
getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;
boolean isNightMode = false;
switch (nightModeFlags) {
case Configuration.UI_MODE_NIGHT_YES:
isNightMode = true;
break;
}
if (isNightMode) {
preferencesUtils.setDarkMode(true);
} else {
preferencesUtils.setDarkMode(false);
}
}
if (preferencesUtils.isDarkMode()) {// after first install
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
} else {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
}
super.onCreate();
}
but for some devices when system is dark and app setting is light there is a color mixing happening between resources.
any useful tips?