Package 

Class BottomSheetBehavior

    • Constructor Detail

      • BottomSheetBehavior

        BottomSheetBehavior()
    • Method Detail

      • setFitToContents

         void setFitToContents(boolean fitToContents)

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

        Parameters:
        fitToContents - whether or not to fit the expanded sheet to its contents.
      • getPeekHeight

         int getPeekHeight()

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

      • setPeekHeight

         void setPeekHeight(int peekHeight)

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

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

         void setGestureInsetBottomIgnored(boolean gestureInsetBottomIgnored)

        Sets whether this bottom sheet should adjust it's position based on the system gesture area onAndroid Q and above.

        Note: the bottom sheet will only adjust it's position if it would be unable to be scrolledupwards because the peekHeight is less than the gesture inset margins,(because that would causea gesture conflict), gesture navigation is enabled, and this {@code ignoreGestureInsetBottom} flag is false.

      • getExpandedOffset

         int getExpandedOffset()

        Returns the current expanded offset. If {@code fitToContents} is true, it will automaticallypick the offset depending on the height of the content.

      • setExpandedOffset

         void setExpandedOffset(int offset)

        Determines the top offset of the BottomSheet in the STATE_EXPANDED state whenfitsToContent is false. The default value is 0, which results in the sheet matching theparent's top.

        Parameters:
        offset - an integer value greater than equal to 0, representing the offset.
      • setHalfExpandedRatio

         void setHalfExpandedRatio(@FloatRange(from = 0.0f, to = 1.0f) float ratio)

        Determines the height of the BottomSheet in the STATE_HALF_EXPANDED state. Thematerial guidelines recommended a value of 0.5, which results in the sheet filling half of theparent. The height of the BottomSheet will be smaller as this ratio is decreased and taller asit is increased. The default value is 0.5.

        Parameters:
        ratio - a float between 0 and 1, representing the STATE_HALF_EXPANDED ratio.
      • setHideable

         void setHideable(boolean hideable)

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

        Parameters:
        hideable - {@code true} to make this bottom sheet hideable.
      • getSkipCollapsed

         boolean getSkipCollapsed()

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

      • setSkipCollapsed

         void setSkipCollapsed(boolean skipCollapsed)

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

        Parameters:
        skipCollapsed - True if the bottom sheet should skip the collapsed state.
      • setDraggable

         void setDraggable(boolean draggable)

        Sets whether this bottom sheet is can be collapsed/expanded by dragging. Note: When disablingdragging, an app will require to implement a custom way to expand/collapse the bottom sheet

        Parameters:
        draggable - {@code false} to prevent dragging the sheet to collapse and expand
      • getState

         int getState()

        Gets the current state of the bottom sheet.

      • onSaveInstanceState

        @NonNull() Parcelable onSaveInstanceState(@NonNull() CoordinatorLayout parent, @NonNull() V child)

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

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

        Parameters:
        parent - the parent CoordinatorLayout
        child - child view to restore from
      • onRestoreInstanceState

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

        Hook allowing a behavior to re-apply a representation of its internal state that hadpreviously been generated by onSaveInstanceState. This function will never be calledwith a null state.

        Parameters:
        parent - the parent CoordinatorLayout
        child - child view to restore from
        state - The frozen state that had previously been returned by .
      • onDetachedFromLayoutParams

         void onDetachedFromLayoutParams()

        Called when the Behavior has been detached from its holding LayoutParams instance.

        This will only be called if the Behavior has been explicitly removed from theLayoutParams instance via setBehavior. It will not be calledif the associated view is removed from the CoordinatorLayout or similar.

      • onLayoutChild

         boolean onLayoutChild(@NonNull() CoordinatorLayout parent, @NonNull() 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 viewin place of the default child layout behavior. The Behavior's implementation can delegate tothe standard CoordinatorLayout measurement behavior by calling parent.onLayoutChild.

        If a Behavior implements onDependentViewChanged to change the position of aview in response to a dependent view changing, it should also implementonLayoutChild in such a way that respects those dependent views.onLayoutChild will always be called for a dependent viewafter its dependency has been laid out.

        Parameters:
        parent - the parent CoordinatorLayout
        child - child view to lay out
        layoutDirection - the resolved layout direction for the CoordinatorLayout, such as LAYOUT_DIRECTION_LTR or LAYOUT_DIRECTION_RTL.
      • onInterceptTouchEvent

         boolean onInterceptTouchEvent(@NonNull() CoordinatorLayout parent, @NonNull() V child, @NonNull() 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 tointercept the rest of the event stream to take an action on its associated child view. Thismethod will return false until it detects the proper intercept conditions, then return trueonce those conditions have occurred.

        Once a Behavior intercepts touch events, the rest of the event stream willbe sent to the onTouchEvent method.

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

        The default implementation of this method always returns false.

        Parameters:
        parent - the parent view currently receiving this touch event
        child - the child view associated with this Behavior
      • onTouchEvent

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

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

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

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

        Parameters:
        parent - the parent view currently receiving this touch event
        child - the child view associated with this Behavior
      • onStartNestedScroll

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

        Called when a descendant of the CoordinatorLayout attempts to initiate a nested scroll.

        Any Behavior associated with any direct child of the CoordinatorLayout may respondto this event and return true to indicate that the CoordinatorLayout should act as a nestedscrolling parent for this scroll. Only Behaviors that return true from this method willreceive subsequent nested scroll events.

        Parameters:
        coordinatorLayout - the CoordinatorLayout parent of the view this Behavior is associatedwith
        child - the child view of the CoordinatorLayout this Behavior is associated with
        directTargetChild - the child view of the CoordinatorLayout that either is or containsthe target of the nested scroll operation
        target - the descendant view of the CoordinatorLayout initiating the nested scroll
        axes - the axes that this nested scroll applies to.
        type - the type of input which cause this scroll event
      • onNestedPreScroll

         void onNestedPreScroll(@NonNull() CoordinatorLayout coordinatorLayout, @NonNull() V child, @NonNull() View target, int dx, int dy, @NonNull() Array<int> consumed, int type)

        Called when a nested scroll in progress is about to update, before the target has consumedany of the scrolled distance.

        Any Behavior associated with the direct child of the CoordinatorLayout may electto accept the nested scroll as part of onStartNestedScroll. Each Behavior thatreturned true will receive subsequent nested scroll events for that nested scroll.

        onNestedPreScroll is called each time the nested scroll is updatedby the nested scrolling child, before the nested scrolling child has consumed the scrolldistance itself. Each Behavior responding to the nested scroll will receive the samevalues. The CoordinatorLayout will report as consumed the maximum number of pixels ineither direction that any Behavior responding to the nested scroll reported as consumed.

        Parameters:
        coordinatorLayout - the CoordinatorLayout parent of the view this Behavior is associatedwith
        child - the child view of the CoordinatorLayout this Behavior is associated with
        target - the descendant view of the CoordinatorLayout performing the nested scroll
        dx - the raw horizontal number of pixels that the user attempted to scroll
        dy - the raw vertical number of pixels that the user attempted to scroll
        consumed - out parameter.
        type - the type of input which cause this scroll event
      • onStopNestedScroll

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

        Called when a nested scroll has ended.

        Any Behavior associated with any direct child of the CoordinatorLayout may electto accept the nested scroll as part of onStartNestedScroll. Each Behavior thatreturned true will receive subsequent nested scroll events for that nested scroll.

        onStopNestedScroll marks the end of a single nested scroll eventsequence. This is a good place to clean up any state related to the nested scroll.

        Parameters:
        coordinatorLayout - the CoordinatorLayout parent of the view this Behavior is associatedwith
        child - the child view of the CoordinatorLayout this Behavior is associated with
        target - the descendant view of the CoordinatorLayout that initiated the nested scroll
        type - the type of input which cause this scroll event
      • onNestedScroll

         void onNestedScroll(@NonNull() CoordinatorLayout coordinatorLayout, @NonNull() V child, @NonNull() View target, int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed, int type, @NonNull() Array<int> consumed)

        Called when a nested scroll in progress has updated and the target has scrolled or attemptedto scroll.

        Any Behavior associated with the direct child of the CoordinatorLayout may electto accept the nested scroll as part of onStartNestedScroll. Each Behavior thatreturned true will receive subsequent nested scroll events for that nested scroll.

        onNestedScroll is called each time the nested scroll is updated by thenested scrolling child, with both consumed and unconsumed components of the scroll suppliedin pixels. Each Behavior responding to the nested scroll will receive the samevalues.

        Parameters:
        coordinatorLayout - the CoordinatorLayout parent of the view this Behavior is associatedwith
        child - the child view of the CoordinatorLayout this Behavior is associated with
        target - the descendant view of the CoordinatorLayout performing the nested scroll
        dxConsumed - horizontal pixels consumed by the target's own scrolling operation
        dyConsumed - vertical pixels consumed by the target's own scrolling operation
        dxUnconsumed - horizontal pixels not consumed by the target's own scrolling operation,but requested by the user
        dyUnconsumed - vertical pixels not consumed by the target's own scrolling operation, butrequested by the user
        type - the type of input which cause this scroll event
        consumed - output.
      • onNestedPreFling

         boolean onNestedPreFling(@NonNull() CoordinatorLayout coordinatorLayout, @NonNull() V child, @NonNull() 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 electto accept the nested scroll as part of onStartNestedScroll. Each Behavior thatreturned true will receive subsequent nested scroll events for that nested scroll.

        onNestedPreFling is called when the current nested scrolling child viewdetects the proper conditions for a fling, but it has not acted on it yet. A Behavior canreturn 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 - the CoordinatorLayout parent of the view this Behavior is associatedwith
        child - the child view of the CoordinatorLayout this Behavior is associated with
        target - the descendant view of the CoordinatorLayout performing the nested scroll
        velocityX - horizontal velocity of the attempted fling
        velocityY - vertical velocity of the attempted fling
      • isHideable

         boolean isHideable()

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

      • isGestureInsetBottomIgnored

         boolean isGestureInsetBottomIgnored()

        Returns whether this bottom sheet should adjust it's position based on the system gesturearea.