我使用以下代码在我的应用程序中在白天/夜间模式之间切换:
SharedPreferences.Editor editor = sharedPrefs.edit();
AppCompatDelegate.setDefaultNightMode(isChecked
? AppCompatDelegate.MODE_NIGHT_YES
: AppCompatDelegate.MODE_NIGHT_NO);
if (isChecked) {
editor.putBoolean("isDarkModeEnabled", true);
editor.apply();
} else {
editor.putBoolean("isDarkModeEnabled", false);
editor.apply();
}
Run Code Online (Sandbox Code Playgroud)
当我切换模式时,活动会闪烁并重新创建。如何在切换模式时实现更平滑的过渡(例如切换之间的淡入/淡出)?我可以使用 overridePendingTransition(),还是还有其他方便的方法?