14

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 bug? This is my code:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    >

    <LinearLayout
        android:id="@+id/llScroll"
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:orientation="vertical"
        android:background="@color/blue_1"
        app:layout_behavior="android.support.design.widget.BottomSheetBehavior">
    </LinearLayout>

</android.support.design.widget.CoordinatorLayout>
Yin Shudi
  • 217
  • 3
  • 9

2 Answers2

40

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);
Fndroid
  • 465
  • 5
  • 9
  • I have not tried this yet, but i do not find anything in the revision history for bottomsheet: https://developer.android.com/topic/libraries/support-library/revisions.html – kirtan403 Aug 22 '16 at 05:38
  • I found that the setPeekHeight(0) is the best and simplest way to get the old functionality back. – lionscribe Sep 14 '16 at 20:16
5

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.

Community
  • 1
  • 1
cohenadair
  • 2,072
  • 1
  • 22
  • 38