Save the date! Android Dev Summit is coming to Mountain View, CA on November 7-8, 2018.

BottomSheetBehavior

public class BottomSheetBehavior
extends

java.lang.Object
   ↳
     ↳ com.google.android.material.bottomsheet.BottomSheetBehavior<V extends View>


An interaction behavior plugin for a child view of CoordinatorLayout to make it work as a bottom sheet.

Summary

Nested classes

class BottomSheetBehavior.BottomSheetCallback

Callback for monitoring events about bottom sheets. 

class BottomSheetBehavior.SavedState

 

Constants

int PEEK_HEIGHT_AUTO

Peek at the 16:9 ratio keyline of its parent.

int STATE_COLLAPSED

The bottom sheet is collapsed.

int STATE_DRAGGING

The bottom sheet is dragging.

int STATE_EXPANDED

The bottom sheet is expanded.

int STATE_HALF_EXPANDED

The bottom sheet is half-expanded (used when mFitToContents is false).

int STATE_HIDDEN

The bottom sheet is hidden.

int STATE_SETTLING

The bottom sheet is settling.

Public constructors

BottomSheetBehavior()

Default constructor for instantiating BottomSheetBehaviors.

BottomSheetBehavior(Context context, AttributeSet attrs)

Default constructor for inflating BottomSheetBehaviors from layout.

Public methods

static <V extends View> BottomSheetBehavior<V> from(V view)

A utility function to get the BottomSheetBehavior associated with the view.

final int getPeekHeight()

Gets the height of the bottom sheet when it is collapsed.

boolean getSkipCollapsed()

Sets whether this bottom sheet should skip the collapsed state when it is being hidden after it is expanded once.

final int getState()

Gets the current state of the bottom sheet.

boolean isFitToContents()
boolean isHideable()

Gets whether this bottom sheet can hide when it is swiped down.

boolean onInterceptTouchEvent(CoordinatorLayout parent, V child, MotionEvent event)
boolean onLayoutChild(CoordinatorLayout parent, V child, int layoutDirection)
boolean onNestedPreFling(CoordinatorLayout coordinatorLayout, V child, View target, float velocityX, float velocityY)
void onNestedPreScroll(CoordinatorLayout coordinatorLayout, V child, View target, int dx, int dy, int[] consumed, int type)
void onRestoreInstanceState(CoordinatorLayout parent, V child, Parcelable state)
Parcelable onSaveInstanceState(CoordinatorLayout parent, V child)
boolean onStartNestedScroll(CoordinatorLayout coordinatorLayout, V child, View directTargetChild, View target, int axes, int type)
void onStopNestedScroll(CoordinatorLayout coordinatorLayout, V child, View target, int type)
boolean onTouchEvent(CoordinatorLayout parent, V child, MotionEvent event)
void setBottomSheetCallback(BottomSheetBehavior.BottomSheetCallback callback)

Sets a callback to be notified of bottom sheet events.

void setFitToContents(boolean fitToContents)

Sets whether the height of the expanded sheet is determined by the height of its contents, or if it is expanded in two stages (half the height of the parent container, full height of parent container).

void setHideable(boolean hideable)

Sets whether this bottom sheet can hide when it is swiped down.

final void setPeekHeight(int peekHeight)

Sets the height of the bottom sheet when it is collapsed.

void setSkipCollapsed(boolean skipCollapsed)

Sets whether this bottom sheet should skip the collapsed state when it is being hidden after it is expanded once.

final void setState(int state)

Sets the state of the bottom sheet.

Inherited methods

From class java.lang.Object

Constants

PEEK_HEIGHT_AUTO

int PEEK_HEIGHT_AUTO

Peek at the 16:9 ratio keyline of its parent.

This can be used as a parameter for setPeekHeight(int). getPeekHeight() will return this when the value is set.

Constant Value: -1 (0xffffffff)

STATE_COLLAPSED

int STATE_COLLAPSED

The bottom sheet is collapsed.

Constant Value: 4 (0x00000004)

STATE_DRAGGING

int STATE_DRAGGING

The bottom sheet is dragging.

Constant Value: 1 (0x00000001)

STATE_EXPANDED

int STATE_EXPANDED

The bottom sheet is expanded.

Constant Value: 3 (0x00000003)

STATE_HALF_EXPANDED

int STATE_HALF_EXPANDED

The bottom sheet is half-expanded (used when mFitToContents is false).

Constant Value: 6 (0x00000006)

STATE_HIDDEN

int STATE_HIDDEN

The bottom sheet is hidden.

Constant Value: 5 (0x00000005)

STATE_SETTLING

int STATE_SETTLING

The bottom sheet is settling.

Constant Value: 2 (0x00000002)

Public constructors

BottomSheetBehavior

BottomSheetBehavior ()

Default constructor for instantiating BottomSheetBehaviors.

BottomSheetBehavior

BottomSheetBehavior (Context context, 
                AttributeSet attrs)

Default constructor for inflating BottomSheetBehaviors from layout.

Parameters
context Context: The ERROR(/Context).

attrs AttributeSet: The ERROR(/AttributeSet).

Public methods

from

BottomSheetBehavior<V> from (V view)

A utility function to get the BottomSheetBehavior associated with the view.

Parameters
view V: The View with BottomSheetBehavior.

Returns
BottomSheetBehavior<V> The BottomSheetBehavior associated with the view.

getPeekHeight

int getPeekHeight ()

Gets the height of the bottom sheet when it is collapsed.

Returns
int The height of the collapsed bottom sheet in pixels, or PEEK_HEIGHT_AUTO if the sheet is configured to peek automatically at 16:9 ratio keyline

getSkipCollapsed

boolean getSkipCollapsed ()

Sets whether this bottom sheet should skip the collapsed state when it is being hidden after it is expanded once.

Returns
boolean Whether the bottom sheet should skip the collapsed state.

getState

int getState ()

Gets the current state of the bottom sheet.

Returns
int One of STATE_EXPANDED, STATE_HALF_EXPANDED, STATE_COLLAPSED, STATE_DRAGGING, STATE_SETTLING, or STATE_HALF_EXPANDED.

isFitToContents

boolean isFitToContents ()

Returns
boolean whether the height of the expanded sheet is determined by the height of its contents, or if it is expanded in two stages (half the height of the parent container, full height of parent container).

isHideable

boolean isHideable ()

Gets whether this bottom sheet can hide when it is swiped down.

Returns
boolean true if this bottom sheet can hide.

onInterceptTouchEvent

boolean onInterceptTouchEvent (CoordinatorLayout parent, 
                V child, 
                MotionEvent event)

Parameters
parent CoordinatorLayout

child V

event MotionEvent

Returns
boolean

onLayoutChild

boolean onLayoutChild (CoordinatorLayout parent, 
                V child, 
                int layoutDirection)

Parameters
parent CoordinatorLayout

child V

layoutDirection int

Returns
boolean

onNestedPreFling

boolean onNestedPreFling (CoordinatorLayout coordinatorLayout, 
                V child, 
                View target, 
                float velocityX, 
                float velocityY)

Parameters
coordinatorLayout CoordinatorLayout

child V

target View

velocityX float

velocityY float

Returns
boolean

onNestedPreScroll

void onNestedPreScroll (CoordinatorLayout coordinatorLayout, 
                V child, 
                View target, 
                int dx, 
                int dy, 
                int[] consumed, 
                int type)

Parameters
coordinatorLayout CoordinatorLayout

child V

target View

dx int

dy int

consumed int

type int

onRestoreInstanceState

void onRestoreInstanceState (CoordinatorLayout parent, 
                V child, 
                Parcelable state)

Parameters
parent CoordinatorLayout

child V

state Parcelable

onSaveInstanceState

Parcelable onSaveInstanceState (CoordinatorLayout parent, 
                V child)

Parameters
parent CoordinatorLayout

child V

Returns
Parcelable

onStartNestedScroll

boolean onStartNestedScroll (CoordinatorLayout coordinatorLayout, 
                V child, 
                View directTargetChild, 
                View target, 
                int axes, 
                int type)

Parameters
coordinatorLayout CoordinatorLayout

child V

directTargetChild View

target View

axes int

type int

Returns
boolean

onStopNestedScroll

void onStopNestedScroll (CoordinatorLayout coordinatorLayout, 
                V child, 
                View target, 
                int type)

Parameters
coordinatorLayout CoordinatorLayout

child V

target View

type int

onTouchEvent

boolean onTouchEvent (CoordinatorLayout parent, 
                V child, 
                MotionEvent event)

Parameters
parent CoordinatorLayout

child V

event MotionEvent

Returns
boolean

setBottomSheetCallback

void setBottomSheetCallback (BottomSheetBehavior.BottomSheetCallback callback)

Sets a callback to be notified of bottom sheet events.

Parameters
callback BottomSheetBehavior.BottomSheetCallback: The callback to notify when bottom sheet events occur.

setFitToContents

void setFitToContents (boolean fitToContents)

Sets whether the height of the expanded sheet is determined by the height of its contents, or if it is expanded in two stages (half the height of the parent container, full height of parent container). Default value is true.

Parameters
fitToContents boolean: whether or not to fit the expanded sheet to its contents.

setHideable

void setHideable (boolean hideable)

Sets whether this bottom sheet can hide when it is swiped down.

Parameters
hideable boolean: true to make this bottom sheet hideable.

setPeekHeight

void setPeekHeight (int peekHeight)

Sets the height of the bottom sheet when it is collapsed.

Parameters
peekHeight int: The height of the collapsed bottom sheet in pixels, or PEEK_HEIGHT_AUTO to configure the sheet to peek automatically at 16:9 ratio keyline.

setSkipCollapsed

void setSkipCollapsed (boolean skipCollapsed)

Sets whether this bottom sheet should skip the collapsed state when it is being hidden after it is expanded once. Setting this to true has no effect unless the sheet is hideable.

Parameters
skipCollapsed boolean: True if the bottom sheet should skip the collapsed state.

setState

void setState (int state)

Sets the state of the bottom sheet. The bottom sheet will transition to that state with animation.

Parameters
state int: One of STATE_COLLAPSED, STATE_EXPANDED, STATE_HIDDEN, or STATE_HALF_EXPANDED.