DayNight theme always shows night theme

2019-06-14 15:14发布

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

2条回答
倾城 Initia
2楼-- · 2019-06-14 15:20

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.

查看更多
爷、活的狠高调
3楼-- · 2019-06-14 15:34

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

查看更多
登录 后发表回答