Android – drawable already belongs to another owner but does not expose constant state

Error: invalid drawable added to layerdrawable! Drawable already belongs to another owner but does not expose constant state

I suddenly found this error today. I'm not sure if it's because I just updated my test device to Android 8.0. The error message clearly indicates that there is a problem with setting the ripple effect on the floating action button, and there is no ripple effect when pressing the button. However, I'm not sure what caused this problem. In fact, The same error is thrown twice in a row. Any help will be appreciated! The rest of the application is still working, but the error really bothers me

Note: minsdkversion is 22, targetsdkversion and compiledsdkversion are 27

In myactivity, line 117 is data binding and setting content view

ActivityMyBinding binding = DataBindingUtil.setContentView(
            this, R.layout.activity_my);

This is the complete stack trace:

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)

resolvent:

Changed app: srccoat = "@ Android: drawable /..." to Android: SRC = "@ Android: drawable /..." fixed it for me

Strange... No matter who posted the answer, they pointed out the solution to me, but they deleted the answer. =/

They mentioned how drawable has status. If it is assigned to multiple floating operation buttons, there will be a problem tracking the status of drawable. Obviously, this problem has been fixed in the recent update. This made me realize that I use app: srccoat instead of Android: SRC to set the source code of fab

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>