BottomSheetBehavior Illegal state argument: 5
For me problem was resolved by sheetBehavior.setHideable(true);
It seems when setHideable
is false and then setting state to BottomSheetBehavior.STATE_HIDDEN
exception will occurred
public class IllegalArgumentException extends RuntimeException
Thrown to indicate that a method has been passed an illegal or inappropriate argument.
Somewhere in your code, you are passing an illegal argument to the method startSettlingAnimation()
(BottomSheetBehavior
class). This method is throwing the exception:
void startSettlingAnimation(View child, int state) {
int top;
if (state == STATE_COLLAPSED) {
top = mCollapsedOffset;
} else if (state == STATE_HALF_EXPANDED) {
top = mHalfExpandedOffset;
} else if (state == STATE_EXPANDED) {
top = getExpandedOffset();
} else if (mHideable && state == STATE_HIDDEN) {
top = mParentHeight;
} else {
throw new IllegalArgumentException("Illegal state argument: " + state);
}
if (mViewDragHelper.smoothSlideViewTo(child, child.getLeft(), top)) {
setStateInternal(STATE_SETTLING);
ViewCompat.postOnAnimation(child, new SettleRunnable(child, state));
} else {
setStateInternal(state);
}
}
Your error is: Illegal state argument: 5
. 5 is the int value of STATE_HIDDEN
. So while your state is STATE_HIDDEN
(5), your mHideable
boolean is false. So, the basic suggestion would be to set the mHideable = true;
Without any code, that's as much as I can tell you.
As @Serj Ardovic explain it s the Hideable
I wanted to add that you can also put it in the xml :
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/bottom_sheet"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:behavior_hideable="true" <- this here
app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior">