Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hidden state of the Bottom Sheet

I am trying to set hidden state for BottomSheet, but it doesn't work. What's the problem?

 bottomBar = BottomSheetBehavior.from(findViewById(R.id.bottom_bar));
 bottomBar.setState(BottomSheetBehavior.STATE_HIDDEN);
like image 459
Nick Avatar asked Feb 09 '17 16:02

Nick


People also ask

What is bottom sheet behavior?

Bottom Sheet is a well-written material design component that performs enter/exit animations, respond to dragging/swiping gestures, etc. For using it in your project you should implement next dependencies into your app build.gradle file: implementation "androidx.coordinatorlayout:coordinatorlayout:1.1.0"

What is bottom sheet in Android?

Bottom sheets are supplementary surfaces primarily used on mobile. There are three types suitable for different use cases: Standard bottom sheets display content that complements the screen's primary content. They remain visible while users interact with the primary content.

How do you use a bottom sheet?

The modal Bottom sheet always appears from the bottom of the screen and if the user clicks on the outside content then it is dismissed. It can be dragged vertically and can be dismissed by sliding it down.

How do I disable BottomSheetDialogFragment dragging?

Disable drag of BottomSheetDialogFragment Even if we have made the BottomSheetDialogFragment as expanded, user can hold the top part of the BottomSheet and drag to show peek view. It can also be disabled by overriding onStateChanged() . This will set the expanded state even if user drags the view.


2 Answers

Remember to add this while hiding the bottom sheet at start of activity/fragment

bottomSheetBehavior =BottomSheetBehavior.from(bottom_sheet_view_here);
bottomSheetBehavior.setHideable(true);//Important to add
bottomSheetBehavior.setState(BottomSheetBehavior.STATE_HIDDEN);
like image 160
zohaib khaliq Avatar answered Oct 13 '22 12:10

zohaib khaliq


mBottomSheetBehaviour.setPeekHeight(0);

use this and it will hide.

like image 33
Akshay Shah Avatar answered Oct 13 '22 12:10

Akshay Shah