Skip to content

Most visited

Recently visited

navigation
added in version 24.1.0
belongs to Maven artifact com.android.support:design:27.0.0

BottomSheetBehavior

public class BottomSheetBehavior
extends Behavior<V extends View>

java.lang.Object
   ↳ android.support.design.widget.CoordinatorLayout.Behavior<V extends android.view.View>
     ↳ android.support.design.widget.BottomSheetBehavior<V extends android.view.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

 

XML attributes

BottomSheetBehavior_Layout_behavior_hideable  
BottomSheetBehavior_Layout_behavior_peekHeight  
BottomSheetBehavior_Layout_behavior_skipCollapsed  

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_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 isHideable()

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

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

Respond to CoordinatorLayout touch events before they are dispatched to child views.

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

Called when the parent CoordinatorLayout is about the lay out the given child view.

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

Called when a nested scrolling child is about to start a fling.

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

This method is deprecated. You should now override onNestedPreScroll(CoordinatorLayout, View, View, int, int, int[], int). This method will still continue to be called if the type is TYPE_TOUCH.

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

Hook allowing a behavior to re-apply a representation of its internal state that had previously been generated by onSaveInstanceState(CoordinatorLayout, V).

Parcelable onSaveInstanceState(CoordinatorLayout parent, V child)

Hook allowing a behavior to generate a representation of its internal state that can later be used to create a new instance with that same state.

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

This method is deprecated. You should now override onStartNestedScroll(CoordinatorLayout, View, View, View, int, int). This method will still continue to be called if the type is TYPE_TOUCH.

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

This method is deprecated. You should now override onStopNestedScroll(CoordinatorLayout, View, View, int). This method will still continue to be called if the type is TYPE_TOUCH.

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

Respond to CoordinatorLayout touch events after this Behavior has started intercepting them.

void setBottomSheetCallback(BottomSheetBehavior.BottomSheetCallback callback)

Sets a callback to be notified of bottom sheet events.

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 android.support.design.widget.CoordinatorLayout.Behavior
From class java.lang.Object

XML attributes

BottomSheetBehavior_Layout_behavior_hideable

Related methods:

BottomSheetBehavior_Layout_behavior_peekHeight

Related methods:

BottomSheetBehavior_Layout_behavior_skipCollapsed

Related methods:

Constants

PEEK_HEIGHT_AUTO

added in version 25.1.0
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

added in version 24.1.0
int STATE_COLLAPSED

The bottom sheet is collapsed.

Constant Value: 4 (0x00000004)

STATE_DRAGGING

added in version 24.1.0
int STATE_DRAGGING

The bottom sheet is dragging.

Constant Value: 1 (0x00000001)

STATE_EXPANDED

added in version 24.1.0
int STATE_EXPANDED

The bottom sheet is expanded.

Constant Value: 3 (0x00000003)

STATE_HIDDEN

added in version 24.1.0
int STATE_HIDDEN

The bottom sheet is hidden.

Constant Value: 5 (0x00000005)

STATE_SETTLING

added in version 24.1.0
int STATE_SETTLING

The bottom sheet is settling.

Constant Value: 2 (0x00000002)

Public constructors

BottomSheetBehavior

added in version 24.1.0
BottomSheetBehavior ()

Default constructor for instantiating BottomSheetBehaviors.

BottomSheetBehavior

added in version 24.1.0
BottomSheetBehavior (Context context, 
                AttributeSet attrs)

Default constructor for inflating BottomSheetBehaviors from layout.

Parameters
context Context: The Context.

attrs AttributeSet: The AttributeSet.

Public methods

from

added in version 24.1.0
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

added in version 24.1.0
int getPeekHeight ()

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

Related XML Attributes:

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

added in version 24.1.0
boolean getSkipCollapsed ()

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

Related XML Attributes:

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

getState

added in version 24.1.0
int getState ()

Gets the current state of the bottom sheet.

Returns
int One of STATE_EXPANDED, STATE_COLLAPSED, STATE_DRAGGING, and STATE_SETTLING.

isHideable

added in version 24.1.0
boolean isHideable ()

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

Related XML Attributes:

Returns
boolean true if this bottom sheet can hide.

onInterceptTouchEvent

added in version 24.1.0
boolean onInterceptTouchEvent (CoordinatorLayout parent, 
                V child, 
                MotionEvent event)

Respond to CoordinatorLayout touch events before they are dispatched to child views.

Behaviors can use this to monitor inbound touch events until one decides to intercept the rest of the event stream to take an action on its associated child view. This method will return false until it detects the proper intercept conditions, then return true once those conditions have occurred.

Once a Behavior intercepts touch events, the rest of the event stream will be sent to the onTouchEvent(CoordinatorLayout, V, MotionEvent) method.

This method will be called regardless of the visibility of the associated child of the behavior. If you only wish to handle touch events when the child is visible, you should add a check to isShown() on the given child.

The default implementation of this method always returns false.

Parameters
parent CoordinatorLayout: the parent view currently receiving this touch event

child V: the child view associated with this Behavior

event MotionEvent: the MotionEvent describing the touch event being processed

Returns
boolean true if this Behavior would like to intercept and take over the event stream. The default always returns false.

onLayoutChild

added in version 24.1.0
boolean onLayoutChild (CoordinatorLayout parent, 
                V child, 
                int layoutDirection)

Called when the parent CoordinatorLayout is about the lay out the given child view.

This method can be used to perform custom or modified layout of a child view in place of the default child layout behavior. The Behavior's implementation can delegate to the standard CoordinatorLayout measurement behavior by calling parent.onLayoutChild.

If a Behavior implements onDependentViewChanged(CoordinatorLayout, android.view.View, android.view.View) to change the position of a view in response to a dependent view changing, it should also implement onLayoutChild in such a way that respects those dependent views. onLayoutChild will always be called for a dependent view after its dependency has been laid out.

Parameters
parent CoordinatorLayout: the parent CoordinatorLayout

child V: child view to lay out

layoutDirection int: the resolved layout direction for the CoordinatorLayout, such as LAYOUT_DIRECTION_LTR or LAYOUT_DIRECTION_RTL.

Returns
boolean true if the Behavior performed layout of the child view, false to request default layout behavior

onNestedPreFling

added in version 24.1.0
boolean onNestedPreFling (CoordinatorLayout coordinatorLayout, 
                V child, 
                View target, 
                float velocityX, 
                float velocityY)

Called when a nested scrolling child is about to start a fling.

Any Behavior associated with the direct child of the CoordinatorLayout may elect to accept the nested scroll as part of onStartNestedScroll(CoordinatorLayout, V, View, View, int). Each Behavior that returned true will receive subsequent nested scroll events for that nested scroll.

onNestedPreFling is called when the current nested scrolling child view detects the proper conditions for a fling, but it has not acted on it yet. A Behavior can return true to indicate that it consumed the fling. If at least one Behavior returns true, the fling should not be acted upon by the child.

Parameters
coordinatorLayout CoordinatorLayout: the CoordinatorLayout parent of the view this Behavior is associated with

child V: the child view of the CoordinatorLayout this Behavior is associated with

target View: the descendant view of the CoordinatorLayout performing the nested scroll

velocityX float: horizontal velocity of the attempted fling

velocityY float: vertical velocity of the attempted fling

Returns
boolean true if the Behavior consumed the fling

onNestedPreScroll

added in version 24.1.0
void onNestedPreScroll (CoordinatorLayout coordinatorLayout, 
                V child, 
                View target, 
                int dx, 
                int dy, 
                int[] consumed)

This method is deprecated.
You should now override onNestedPreScroll(CoordinatorLayout, View, View, int, int, int[], int). This method will still continue to be called if the type is TYPE_TOUCH.

Parameters
coordinatorLayout CoordinatorLayout

child V

target View

dx int

dy int

consumed int

onRestoreInstanceState

added in version 24.1.0
void onRestoreInstanceState (CoordinatorLayout parent, 
                V child, 
                Parcelable state)

Hook allowing a behavior to re-apply a representation of its internal state that had previously been generated by onSaveInstanceState(CoordinatorLayout, V). This function will never be called with a null state.

Parameters
parent CoordinatorLayout: the parent CoordinatorLayout

child V: child view to restore from

state Parcelable: The frozen state that had previously been returned by onSaveInstanceState(CoordinatorLayout, V).

onSaveInstanceState

added in version 24.1.0
Parcelable onSaveInstanceState (CoordinatorLayout parent, 
                V child)

Hook allowing a behavior to generate a representation of its internal state that can later be used to create a new instance with that same state. This state should only contain information that is not persistent or can not be reconstructed later.

Behavior state is only saved when both the parent CoordinatorLayout and a view using this behavior have valid IDs set.

Parameters
parent CoordinatorLayout: the parent CoordinatorLayout

child V: child view to restore from

Returns
Parcelable Returns a Parcelable object containing the behavior's current dynamic state.

onStartNestedScroll

added in version 24.1.0
boolean onStartNestedScroll (CoordinatorLayout coordinatorLayout, 
                V child, 
                View directTargetChild, 
                View target, 
                int nestedScrollAxes)

This method is deprecated.
You should now override onStartNestedScroll(CoordinatorLayout, View, View, View, int, int). This method will still continue to be called if the type is TYPE_TOUCH.

Parameters
coordinatorLayout CoordinatorLayout

child V

directTargetChild View

target View

nestedScrollAxes int

Returns
boolean

onStopNestedScroll

added in version 24.1.0
void onStopNestedScroll (CoordinatorLayout coordinatorLayout, 
                V child, 
                View target)

This method is deprecated.
You should now override onStopNestedScroll(CoordinatorLayout, View, View, int). This method will still continue to be called if the type is TYPE_TOUCH.

Parameters
coordinatorLayout CoordinatorLayout

child V

target View

onTouchEvent

added in version 24.1.0
boolean onTouchEvent (CoordinatorLayout parent, 
                V child, 
                MotionEvent event)

Respond to CoordinatorLayout touch events after this Behavior has started intercepting them.

Behaviors may intercept touch events in order to help the CoordinatorLayout manipulate its child views. For example, a Behavior may allow a user to drag a UI pane open or closed. This method should perform actual mutations of view layout state.

This method will be called regardless of the visibility of the associated child of the behavior. If you only wish to handle touch events when the child is visible, you should add a check to isShown() on the given child.

Parameters
parent CoordinatorLayout: the parent view currently receiving this touch event

child V: the child view associated with this Behavior

event MotionEvent: the MotionEvent describing the touch event being processed

Returns
boolean true if this Behavior handled this touch event and would like to continue receiving events in this stream. The default always returns false.

setBottomSheetCallback

added in version 24.1.0
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.

setHideable

added in version 24.1.0
void setHideable (boolean hideable)

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

Related XML Attributes:

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

setPeekHeight

added in version 24.1.0
void setPeekHeight (int peekHeight)

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

Related XML Attributes:

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

added in version 24.1.0
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.

Related XML Attributes:

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

setState

added in version 24.1.0
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, or STATE_HIDDEN.

This site uses cookies to store your preferences for site-specific language and display options.

Get the latest Android developer news and tips that will help you find success on Google Play.

* Required Fields

Hooray!

Follow Google Developers on WeChat

Browse this site in ?

You requested a page in , but your language preference for this site is .

Would you like to change your language preference and browse this site in ? If you want to change your language preference later, use the language menu at the bottom of each page.

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.

Take a short survey?
Help us improve the Android developer experience.
(Sep 2017 survey)