Search code examples
androidbottom-sheet

Standard Bottom Sheet with snap to STATE_EXPANDED, STATE_HALF_EXPANDED and STATE_COLLAPSED


Is it possible to make a Standard Bottom Sheet snap to these three states?

  • STATE_EXPANDED
  • STATE_HALF_EXPANDED
  • STATE_COLLAPSED

By default it already snaps to STATE_EXPANDED and STATE_COLLAPSED but not to STATE_HALF_EXPANDED.


Solution

  • I've just found out how one can achieve it by reading BottomSheetBehavior.java.

    If you read that class, you'll find the following snippet of code:

    enter image description here

    As you can see, the code will only consider snapping to the STATE_HALF_EXPANDED state if fitToContents is equals to false.
    So setting this flag to false is the answer to the question.