android – Drawable已经属于另一个所有者但不暴露常量状态
作者:互联网
错误:添加到LayerDrawable的无效drawable! Drawable已经属于另一个所有者但不暴露常量状态.
我今天突然发现了这个错误,我不确定是不是因为我刚刚将我的测试设备更新到Android 8.0.错误消息清楚地表明在浮动动作按钮上设置涟漪效果有问题,并且按下按钮时确实没有涟漪效应.但是,我不确定是什么导致了这个问题.实际上,完全相同的错误连续两次抛出.任何帮助将非常感激!该应用程序的其余部分仍然正常运行,但该错误真的困扰我.
附: minSdkVersion是22,targetSdkVersion和compiledSdkVersion是27
在MyActivity中,第117行是数据绑定和设置内容视图.
ActivityMyBinding binding = DataBindingUtil.setContentView(
this, R.layout.activity_my);
这是完整的堆栈跟踪:
W/LayerDrawable: Invalid drawable added to LayerDrawable! Drawable already belongs to another owner but does not expose a constant state.
java.lang.RuntimeException
at android.graphics.drawable.LayerDrawable$ChildDrawable.<init>(LayerDrawable.java:1855)
at android.graphics.drawable.LayerDrawable$LayerState.<init>(LayerDrawable.java:1975)
at android.graphics.drawable.LayerDrawable.createConstantState(LayerDrawable.java:168)
at android.graphics.drawable.LayerDrawable.mutate(LayerDrawable.java:1779)
at android.graphics.drawable.LayerDrawable.mutate(LayerDrawable.java:1785)
at android.graphics.drawable.RippleDrawable.mutate(RippleDrawable.java:997)
at android.view.View.applyBackgroundTint(View.java:21809)
at android.view.View.setBackgroundDrawable(View.java:21680)
at android.support.design.widget.FloatingActionButton.access$001(FloatingActionButton.java:68)
at android.support.design.widget.FloatingActionButton$ShadowDelegateImpl.setBackgroundDrawable(FloatingActionButton.java:824)
at android.support.design.widget.FloatingActionButtonLollipop.setBackgroundDrawable(FloatingActionButtonLollipop.java:73)
at android.support.design.widget.FloatingActionButton.<init>(FloatingActionButton.java:179)
at android.support.design.widget.FloatingActionButton.<init>(FloatingActionButton.java:151)
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:334)
at android.view.LayoutInflater.createView(LayoutInflater.java:647)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:790)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
at android.databinding.DataBindingUtil.setContentView(DataBindingUtil.java:276)
at android.databinding.DataBindingUtil.setContentView(DataBindingUtil.java:261)
at com.generica.genericb.genericc.MyActivity.onCreate(MyActivity.java:117)
at android.app.Activity.performCreate(Activity.java:7174)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1220)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2908)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3030)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1696)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6938)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
解决方法:
更改app:srcCompat =“@ android:drawable / …”到android:src =“@ android:drawable / …”为我修复了它.
奇怪……无论谁发布了答案之前都向我指出了解决方案,但他们删除了答案. = /
他们提到了Drawable如何具有状态,如果将其分配给多个浮动操作按钮,那么跟踪Drawable的状态就会出现问题.显然,最近的更新,此问题已得到修复.这让我意识到我用app:srcCompat而不是android:src来设置FAB的源代码.
标签:android,android-databinding,setcontentview,layerdrawable 来源: https://codeday.me/bug/20190627/1304596.html