问题描述
由于MIUI 11/12使用其自己的暗模式自定义实现,因此使用以下代码会导致ClassCastException和活动生命周期异常,因为DefaultNightMode和LocalNightMode始终未指定,即-100而不是0或1.
Since MIUI 11/12 Use Its Own Custom Implementation of Dark Mode, using below code results in ClassCastExceptionand Activity Life Cycle Exception, as DefaultNightMode and LocalNightMode is always Unspecified i.e. -100 instead of 0 or 1.
如果有人针对MIUI 11/12专门针对小米设备构建了解决方法.请帮我解决这个问题.
If anyone has built a workaround for Xiaomi Devices specially for MIUI 11/12. Please Help Me Out On this.
使用的代码:
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
this.recreate();
导致的错误:
2020-10-25 07:04:43.626 9167-9167/com.xxxx.xxxxxx E/ActivityInjector: get life cycle exception
java.lang.ClassCastException: android.os.BinderProxy cannot be cast to android.app.servertransaction.ClientTransaction
推荐答案
我自己解决了这个问题.经过一个星期的摆弄后,我做到了.
I solved it myself. After fiddling around with it for a week, I did it..
方法如下:
-而不是设置android:forceDarkAllowed ="false"每个活动.
-- Instead of setting android:forceDarkAllowed="false" for each and every Activity.
-只需进入values.xml并将其放置在您的AppTheme中
-- Just goto values.xml and place this in your AppTheme
<item name="android:forceDarkAllowed">false</item>
它将要求您创建一个valuesv29.xml.创建它,并删除forceDarkAllowed ="false".所有活动中.
It will ask you to create a valuesv29.xml. Create it, and remove the forceDarkAllowed="false" from all activities.
欢迎.:)
这篇关于MIUI 11/12主题切换导致LifeCycleException,ClassCastException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!