We implemented night mode to our application. it works like a charm except for its transition. We are using the Base Application class to implement it. The problem is no matter what we tried we couldn't achieve a smooth transition when the configuration changes.
We tried to implement enter and exit animation in our style. But it applies to the whole activity. So it also affects others transitions of the activity. So it didn't work.
As can be seen from the image there is a black blinking appear on the screen when the configuration changes.
Configuration Change Code :
public static void applyTheme(@NonNull String themePref) {
switch (themePref) {
case LIGHT_MODE: {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
Log.d(Statics.LOG_TAG, "Applying day mode");
break;
}
case DARK_MODE: {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
Log.d(Statics.LOG_TAG, "Applying night mode");
break;
}
default: {
Log.d(Statics.LOG_TAG, "Applying automatic mode");
if (BuildCompat.isAtLeastP()) {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM);
} else {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY);
}
break;
}
}
}
Thanks for reading this. Any help is appreciated.