DayNight theme always shows night theme

£可爱£侵袭症+ 提交于 2019-12-23 05:06:05

问题


I've created a new project that only includes a very simple activity that uses the new Day/Night theme. Even when calling AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO); in a static block on the application class AND calling getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_NO); in the activity, the activity is showing the night theme. I've set a break point on the activity and its reporting that the UI mode is night, so I've got no idea why it's refusing to show the day theme.

I'm compiling against/targetting API 23 and testing on a Nexus 5 running Marshmallow


回答1:


See https://code.google.com/p/android/issues/detail?id=201910. This will be fixed in the 23.2.1 bugfix release.

For now, you can force the theme to re-apply using the new configuration in your Activity.onCreate() by calling

getTheme().applyStyle(R.style.Theme_AppCompat_<whatever>, true);

where <whatever> is the theme that you're using in that activity. Once you update to 23.2.1, you will not need this workaround.




回答2:


You also need to call yourAppCompatActivity.getDelegate().applyDayNight();.



来源:https://stackoverflow.com/questions/35643607/daynight-theme-always-shows-night-theme

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!