Reputation: 1929
In my app I have a bottom sheet and a button that makes it collapse/expand.
If peekHeight
is not set the bottom sheet is not draggable and does not collapse, it is always visible.
Here is the code:
View bottomSheet = findViewById(R.id.bottom_sheet1);
mBottomSheetBehavior1 = BottomSheetBehavior.from(bottomSheet);
mBottomSheetBehavior1.setPeekHeight(0); //IF I OMIT THIS, IT DOES NOT WORK
mButton1 = (Button) findViewById(R.id.button_1);
mButton1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(mBottomSheetBehavior1.getState() != BottomSheetBehavior.STATE_EXPANDED) {
mBottomSheetBehavior1.setState(BottomSheetBehavior.STATE_EXPANDED);
mButton1.setText("Collapse 1");
}
else {
mBottomSheetBehavior1.setState(BottomSheetBehavior.STATE_COLLAPSED);
mButton1.setText("Expand 1");
}
}
});
What is wrong?
Upvotes: 2
Views: 1328
Reputation: 62189
By default, BottomSheetBehavior
is not hideable.
You have to explicitly tell, that you want that behavior to be hideable:
bottomSheetBehavior = BottomSheetBehavior.from(bottomSheet);
bottomSheetBehavior.setHideable(true);
Upvotes: 2