I have a bottom sheet with its height and width set to match_parent
. So when on button click I set the behavior to STATE_EXPANDED
like this:
mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
My Bottomsheet is defined as below:
<FrameLayout
android:id="@+id/bottom_sheet"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"
android:elevation="@dimen/design_appbar_elevation"
app:behavior_hideable="true"
app:layout_behavior="@string/bottom_sheet_behavior">
<include
android:id="@+id/bottom_sheet_content"
layout="@layout/bottomsheet_layout" />
</FrameLayout>
I am monitoring states with the BottomSheet Callbacks.
STATE_EXPANDED
STATE_COLLAPSED
STATE_HIDDEN
I don't understand why it stops in the middle. How can I make it hidden with a single swipe.
I tried that by setting peek_height
to 0dp
. By this, it never encounters the STATE_HIDDEN
. When hidden, its state becomes STATE_COLLAPSED
. I just don't understand this states.
How to achieve STATE_HIDDEN
with a single swipe down?
Android Bottom Sheet is a component that slides up from the bottom of the screen having multiple options. Here are the examples of the Bottom sheet from apps. There are two types of bottom sheets, Persistent Bottom Sheet and Modal Bottom Sheet.
Using the Interface - onSlide which as a parameter slideOffSet of type float , can be used to dim the background.
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.
Standard bottom sheets display content that complements the screen's primary content. They remain visible while users interact with the primary content. Modal bottom sheets are an alternative to inline menus or simple dialogs on mobile and provide room for additional items, longer descriptions, and iconography.
Kinda late but I just stumbled upon this while searching for something similar.
This is how you can skip the collapsed state:
In XML by adding app:behavior_skipCollapsed="true"
to the BottomSheet view.
OR
Programmatically with setSkipCollapsed(boolean).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With