Can't hide Bottom Sheet, Android

first you have to add the attribute

app:behavior_hideable="true"

in your

<android.support.v4.widget.NestedScrollView
    android:id="@+id/bottom_sheet"
    android:layout_width="match_parent"
    android:layout_height="350dp"
    android:background="?android:attr/windowBackground"
    android:clipToPadding="true"
    app:layout_behavior="android.support.design.widget.BottomSheetBehavior">

And then you can hide the bottom sheet using

mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_HIDDEN)

and not

mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED)

the state COLLAPSED is between HIDDEN and EXPANDED and his heigth must be specified by the attribute:

app:behavior_peekHeight="200dp"

Write this:

    mBottomSheetBehavior.setPeekHeight(0);

In my case I was using BottomSheetDialog.

app:behavior_hideable - attribute is used to determine if our bottom sheet will hide when it is swiped down. In other words bottom sheet top be off screen, if the peek height isn’t set.

app:behavior_peekHeight - attribute value used to represent how much pixels the bottom sheet will be visible.

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/bottom_sheet_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:elevation="10dp"
android:orientation="vertical"
android:background="@color/colorPrimaryDerived"
app:layout_behavior="@string/bottom_sheet_behavior"
app:behavior_hideable="true"
app:behavior_peekHeight="0dp"> ........... </LinearLayout>

I set the peekHeight to 50dp. And peek height has nothing to do with the bottomSheet layout height itself which I set 200dp (for example only).

peek

You can view the changes in your XML viewer if the bottom sheet is expanded, if so add the app:behavior_peekHeight = 0dpfrom the xml layout and it will hide and also inform you of the current state.