You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
FAB throws RuntimeException: Invalid drawable added to LayerDrawable! Drawable already belongs to another owner but does not expose a constant state.
#46
I'm having problem with the FAB, it's throws this exception and I can't find the reason...
The app is not crashing, but this error occurs twice, one after the other, and this filling my logcat with bunch of code that "hiding" the important lines.
Logcat:
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:1850)
at android.graphics.drawable.LayerDrawable$LayerState.<init>(LayerDrawable.java:1967)
at android.graphics.drawable.LayerDrawable.createConstantState(LayerDrawable.java:168)
at android.graphics.drawable.LayerDrawable.mutate(LayerDrawable.java:1774)
at android.graphics.drawable.LayerDrawable.mutate(LayerDrawable.java:1780)
at android.graphics.drawable.RippleDrawable.mutate(RippleDrawable.java:974)
at android.view.View.applyBackgroundTint(View.java:20532)
at android.view.View.setBackgroundDrawable(View.java:20403)
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 com.idomo.Fab.<init>(Fab.java:17)
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 com.idomo.RecipesListFragment.onCreateView(RecipesListFragment.java:48)
My FAB class:
package com.idomo;
import android.content.Context;
import android.support.design.widget.FloatingActionButton;
import android.util.AttributeSet;
import android.view.View;
import com.gordonwong.materialsheetfab.AnimatedFab;
public class Fab extends FloatingActionButton implements AnimatedFab{
public Fab(Context context){
super(context);
}
public Fab(Context context, AttributeSet attrs){
super(context, attrs); // **The error starts here** (line 17)
}
public Fab(Context context, AttributeSet attrs, int defStyleAttr){
super(context, attrs, defStyleAttr);
}
@Override
public void show(){
show(0, 0);
}
@Override
public void show(float translationX, float translationY){
setVisibility(View.VISIBLE);
}
@Override
public void hide(){
setVisibility(View.INVISIBLE);
}
}
XML (RecipesListFragment):
<!-- Your FAB implementation -->
<com.idomo.Fab
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="start|bottom"
android:layout_margin="@dimen/fab_margin"
android:backgroundTint="@color/colorPrimary"
android:src="@drawable/ic_edit" />
<!-- Overlay that dims the screen -->
<com.gordonwong.materialsheetfab.DimOverlayFrameLayout
android:id="@+id/dim_overlay"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<!-- Circular reveal container for the sheet -->
<io.codetail.widget.RevealLinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="start|bottom"
android:orientation="vertical" />
<!-- Sheet that contains your items -->
<android.support.v7.widget.CardView
android:id="@+id/fab_sheet"
android:layout_width="200dp"
android:layout_height="wrap_content">
<ListView
android:id="@+id/fabMenu"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</ListView>
</android.support.v7.widget.CardView>
Thanks for helpers,
Ido.
The text was updated successfully, but these errors were encountered:
For anyone who comes across this error too, the problem is
android:backgroundTint="@color/colorPrimary".
It helps to set a colorStateList instead, e.g. like this:
int[][] states = new int[][] {
new int[] { android.R.attr.state_enabled},
new int[] { android.R.attr.state_pressed}
};
int[] colors = new int[] {
ContextCompat.getColor(this, R.color.colorFab),
ContextCompat.getColor(this, R.color.colorFabPressed)
};
ColorStateList fabColorList = new ColorStateList(states, colors);
findViewById(R.id.fab).setBackgroundTintList(fabColorList);
I'm having problem with the FAB, it's throws this exception and I can't find the reason...
The app is not crashing, but this error occurs twice, one after the other, and this filling my logcat with bunch of code that "hiding" the important lines.
Logcat:
My FAB class:
XML (RecipesListFragment):
Thanks for helpers,
Ido.
The text was updated successfully, but these errors were encountered: