FAB: Drawable already belongs to another owner

血红的双手。 提交于 2019-12-06 01:36:18

Fixed:

Added xmlns:app="http://schemas.android.com/apk/res-auto" in top layout

Used app:backgroundTint="@color/colorFABTint" instead of android:backgroundTint="#000"

Added following line in colors.xml

<color name="colorFABTint">#000000</color>

Resultant xml:

<RelativeLayout
    android:layout_margin="30dp"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:android="http://schemas.android.com/apk/res/android">

<android.support.design.widget.FloatingActionButton
                android:layout_marginBottom="5dp"
                app:layout_anchorGravity="bottom"
                android:layout_width="wrap_content"
                android:layout_gravity="bottom|end"
                android:layout_height="wrap_content"
                android:src="@drawable/ic_home_account"
                app:backgroundTint="@color/colorFABTint"
                android:id="@+id/fbtn_activity_main_account_manage_addresses"
                app:layout_anchor="@id/fbtn_activity_main_account_edit_account"/>

Drawable has a state, and if you assign it to more than one Floating Action Button, then there will be a problem keeping track of the Drawable's state.

Maybe there is better solutions but one solution may be to set fab icons in onCreate instead of layout you can remove fab src from layout and use this:

fab.setImageResource(getResources().getDrawable(R.drawable.ic_edit_account).mutate());

or maybe this:

fab.setImageResource(getResources().getDrawable(R.drawable.ic_edit_account).getConstantState().newDrawable());
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!