DayNight主题始终显示夜晚主题 [英] DayNight theme always shows night theme

查看:79
本文介绍了DayNight主题始终显示夜晚主题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个新项目,其中仅包含一个使用新的Day/Night主题的非常简单的活动. 即使在应用程序类的静态块中调用AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);并在活动中调用getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_NO);时,活动也会显示夜间主题. 我已经在活动及其报告UI模式为夜晚的情况下设置了一个断点,所以我不知道为什么它拒绝显示白天主题.

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.

我正在针对API 23进行编译/定位,并在运行棉花糖的Nexus 5上进行了测试

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

推荐答案

请参见 https://code.google.com/p/android/issues/detail?id=201910 .这将在23.2.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);

其中<whatever>是您在该活动中使用的主题.更新到23.2.1后,您将不需要此解决方法.

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.

这篇关于DayNight主题始终显示夜晚主题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆