BottomSheetBehavior work properly in
compile \'com.android.support:design:24.1.1\'
but when I update it to 24.2.0,it is not work.Is that a
STATE_COLLAPSED : Hides a part of the bottom sheet
STATE_HIDDEN : Hides complete bottom sheet
In Support Library 24.2.0, you have to set the peek height to indicate how many pixels you want your bottom sheet to show when collapsed.
So if you want it to be collapsed and hid, you can add the code like this after you initialized your BottomSheetBehavior:
mBottomSheetBehavior.setPeekHeight(0);
that means when the bottom sheet collapsed, 0 pixel of its height will be shown.
Or your can just make it disappear if you need, use the code like this:
mBottomSheetBehavior.setHideable(true);
mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_HIDDEN);
Updated August 30th, 2016
The accepted answer explains the difference between STATE_HIDDEN
and STATE_COLLAPSED
and how to correctly use both in com.android.support:design:24.2.0
.
As of August 20th, 2016
Although this does seem to be a bug with com.android.support:design:24.2.0
, you can temporarily work around it by using BottomSheetBehavior.STATE_HIDDEN
:
mBehavior.setHideable(true);
mBehavior.setState(BottomSheetBehavior.STATE_HIDDEN);
This will still close the bottom sheet with an animation.
I'm not sure what the actual difference between STATE_COLLAPSED
and STATE_HIDDEN
is, and the documentation is less than helpful, but until it's actually fixed I think STATE_HIDDEN
is okay.