在android中切换到黑暗模式不是很顺利
我正在为我的应用程序使用material components DayNight主题。我想在运行时打开/关闭黑暗模式。我正在使用以下方法更改应用程序的主题:在android中切换到黑暗模式不是很顺利,android,Android,我正在为我的应用程序使用material components DayNight主题。我想在运行时打开/关闭黑暗模式。我正在使用以下方法更改应用程序的主题: AppCompatDelegate.setDefaultNightMode(); 问题是,它重新创建的活动不是很顺利。在更改应用程序主题之前,它会显示一个黑屏 有什么方法可以让它看起来平滑吗?在调用super.create方法之前将主题设置为暗模式,这样在用户看到活动之前,它的主题将首先更改 protected void onCreat
AppCompatDelegate.setDefaultNightMode();
问题是,它重新创建的活动不是很顺利。在更改应用程序主题之前,它会显示一个黑屏
有什么方法可以让它看起来平滑吗?在调用super.create方法之前将主题设置为暗模式,这样在用户看到活动之前,它的主题将首先更改
protected void onCreate(Bundle savedInstanceState) {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
希望这有帮助。我正在应用程序类中设置暗模式。同时调用setDetaultNightMode应该会重新创建活动,这对我来说是不可能的。感谢您的回答。尽管这只发生在模拟器中。在设备中工作平稳。