BaseTransientBottomBar

public abstract class BaseTransientBottomBar
extends Object

java.lang.Object
   ↳ com.google.android.material.snackbar.BaseTransientBottomBar<B extends com.google.android.material.snackbar.BaseTransientBottomBar<B>>


Base class for lightweight transient bars that are displayed along the bottom edge of the application window.

Summary

Nested classes

class BaseTransientBottomBar.BaseCallback<B>

Base class for BaseTransientBottomBar callbacks. 

class BaseTransientBottomBar.Behavior

Behavior for BaseTransientBottomBar

interface BaseTransientBottomBar.ContentViewCallback

This interface is deprecated. Use ContentViewCallback instead.  

Constants

int ANIMATION_MODE_FADE

Animation mode that corresponds to the fade in and out animations.

int ANIMATION_MODE_SLIDE

Animation mode that corresponds to the slide in and out animations.

int LENGTH_INDEFINITE

Show the Snackbar indefinitely.

int LENGTH_LONG

Show the Snackbar for a long period of time.

int LENGTH_SHORT

Show the Snackbar for a short period of time.

Fields

protected final BaseTransientBottomBar.SnackbarBaseLayout view

Protected constructors

BaseTransientBottomBar(ViewGroup parent, View content, ContentViewCallback contentViewCallback)

Constructor for the transient bottom bar.

BaseTransientBottomBar(Context context, ViewGroup parent, View content, ContentViewCallback contentViewCallback)

Public methods

B addCallback(BaseCallback<B> callback)

Adds the specified callback to the list of callbacks that will be notified of transient bottom bar events.

void dismiss()

Dismiss the BaseTransientBottomBar.

View getAnchorView()

Returns the anchor view for this BaseTransientBottomBar.

int getAnimationMode()

Returns the animation mode.

BaseTransientBottomBar.Behavior getBehavior()

Return the behavior.

Context getContext()

Returns the BaseTransientBottomBar's context.

int getDuration()

Return the duration.

View getView()

Returns the BaseTransientBottomBar's view.

boolean isAnchorViewLayoutListenerEnabled()

Returns whether the anchor view layout listener is enabled.

boolean isGestureInsetBottomIgnored()

Returns whether this bottom bar should adjust it's position based on the system gesture area on Android Q and above.

boolean isShown()

Return whether this BaseTransientBottomBar is currently being shown.

boolean isShownOrQueued()

Returns whether this BaseTransientBottomBar is currently being shown, or is queued to be shown next.

B removeCallback(BaseCallback<B> callback)

Removes the specified callback from the list of callbacks that will be notified of transient bottom bar events.

B setAnchorView(int anchorViewId)

Sets the view the BaseTransientBottomBar should be anchored above by id.

B setAnchorView(View anchorView)

Sets the view the BaseTransientBottomBar should be anchored above.

void setAnchorViewLayoutListenerEnabled(boolean anchorViewLayoutListenerEnabled)

Sets whether the anchor view layout listener is enabled.

B setAnimationMode(int animationMode)

Sets the animation mode.

B setBehavior(BaseTransientBottomBar.Behavior behavior)

Sets the BaseTransientBottomBar.Behavior to be used in this BaseTransientBottomBar.

B setDuration(int duration)

Set how long to show the view for.

B setGestureInsetBottomIgnored(boolean gestureInsetBottomIgnored)

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

void show()

Show the BaseTransientBottomBar.

Protected methods

void dispatchDismiss(int event)
SwipeDismissBehavior<? extends View> getNewBehavior()
int getSnackbarBaseLayoutResId()
boolean hasSnackbarStyleAttr()

Snackbars should still work with AppCompat themes, which don't specify a snackbarStyle.

Inherited methods

Constants

ANIMATION_MODE_FADE

public static final int ANIMATION_MODE_FADE

Animation mode that corresponds to the fade in and out animations.

Constant Value: 1 (0x00000001)

ANIMATION_MODE_SLIDE

public static final int ANIMATION_MODE_SLIDE

Animation mode that corresponds to the slide in and out animations.

Constant Value: 0 (0x00000000)

LENGTH_INDEFINITE

public static final int LENGTH_INDEFINITE

Show the Snackbar indefinitely. This means that the Snackbar will be displayed from the time that is shown until either it is dismissed, or another Snackbar is shown.

See also:

Constant Value: -2 (0xfffffffe)

LENGTH_LONG

public static final int LENGTH_LONG

Show the Snackbar for a long period of time.

See also:

Constant Value: 0 (0x00000000)

LENGTH_SHORT

public static final int LENGTH_SHORT

Show the Snackbar for a short period of time.

See also:

Constant Value: -1 (0xffffffff)

Fields

view

protected final BaseTransientBottomBar.SnackbarBaseLayout view

Protected constructors

BaseTransientBottomBar

protected BaseTransientBottomBar (ViewGroup parent, 
                View content, 
                ContentViewCallback contentViewCallback)

Constructor for the transient bottom bar.

Uses Context from parent.

Parameters
parent ViewGroup: The parent for this transient bottom bar.

content View: The content view for this transient bottom bar.

contentViewCallback ContentViewCallback: The content view callback for this transient bottom bar.

BaseTransientBottomBar

protected BaseTransientBottomBar (Context context, 
                ViewGroup parent, 
                View content, 
                ContentViewCallback contentViewCallback)

Parameters
context Context

parent ViewGroup

content View

contentViewCallback ContentViewCallback

Public methods

addCallback

public B addCallback (BaseCallback<B> callback)

Adds the specified callback to the list of callbacks that will be notified of transient bottom bar events.

Parameters
callback BaseCallback: Callback to notify when transient bottom bar events occur.

Returns
B

dismiss

public void dismiss ()

Dismiss the BaseTransientBottomBar.

getAnchorView

public View getAnchorView ()

Returns the anchor view for this BaseTransientBottomBar.

Returns
View

getAnimationMode

public int getAnimationMode ()

Returns the animation mode.

Returns
int

getBehavior

public BaseTransientBottomBar.Behavior getBehavior ()

Return the behavior.

Returns
BaseTransientBottomBar.Behavior

getContext

public Context getContext ()

Returns the BaseTransientBottomBar's context.

Returns
Context

getDuration

public int getDuration ()

Return the duration.

Returns
int

See also:

getView

public View getView ()

Returns the BaseTransientBottomBar's view.

Returns
View

isAnchorViewLayoutListenerEnabled

public boolean isAnchorViewLayoutListenerEnabled ()

Returns whether the anchor view layout listener is enabled.

Returns
boolean

isGestureInsetBottomIgnored

public boolean isGestureInsetBottomIgnored ()

Returns whether this bottom bar should adjust it's position based on the system gesture area on Android Q and above. See setGestureInsetBottomIgnored(boolean).

Returns
boolean

isShown

public boolean isShown ()

Return whether this BaseTransientBottomBar is currently being shown.

Returns
boolean

isShownOrQueued

public boolean isShownOrQueued ()

Returns whether this BaseTransientBottomBar is currently being shown, or is queued to be shown next.

Returns
boolean

removeCallback

public B removeCallback (BaseCallback<B> callback)

Removes the specified callback from the list of callbacks that will be notified of transient bottom bar events.

Parameters
callback BaseCallback: Callback to remove from being notified of transient bottom bar events

Returns
B

setAnchorView

public B setAnchorView (int anchorViewId)

Sets the view the BaseTransientBottomBar should be anchored above by id.

Parameters
anchorViewId int

Returns
B

Throws
IllegalArgumentException if the anchor view is not found.

setAnchorView

public B setAnchorView (View anchorView)

Sets the view the BaseTransientBottomBar should be anchored above.

Parameters
anchorView View

Returns
B

setAnchorViewLayoutListenerEnabled

public void setAnchorViewLayoutListenerEnabled (boolean anchorViewLayoutListenerEnabled)

Sets whether the anchor view layout listener is enabled. If enabled, the BaseTransientBottomBar will recalculate and update its position when the position of the anchor view is changed.

Parameters
anchorViewLayoutListenerEnabled boolean

setAnimationMode

public B setAnimationMode (int animationMode)

Sets the animation mode.

Parameters
animationMode int: of ANIMATION_MODE_SLIDE or ANIMATION_MODE_FADE.

Returns
B

See also:

setBehavior

public B setBehavior (BaseTransientBottomBar.Behavior behavior)

Sets the BaseTransientBottomBar.Behavior to be used in this BaseTransientBottomBar.

Parameters
behavior BaseTransientBottomBar.Behavior: BaseTransientBottomBar.Behavior to be applied.

Returns
B

setDuration

public B setDuration (int duration)

Set how long to show the view for.

Parameters
duration int: How long to display the message. Can be LENGTH_SHORT, LENGTH_LONG, LENGTH_INDEFINITE, or a custom duration in milliseconds.

Returns
B

setGestureInsetBottomIgnored

public B setGestureInsetBottomIgnored (boolean gestureInsetBottomIgnored)

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

Note: the bottom bar will only adjust it's position if it is dismissable via swipe (because that would cause a gesture conflict), gesture navigation is enabled, and this gestureInsetBottomIgnored flag is false.

Parameters
gestureInsetBottomIgnored boolean

Returns
B

show

public void show ()

Show the BaseTransientBottomBar.

Protected methods

dispatchDismiss

protected void dispatchDismiss (int event)

Parameters
event int

getNewBehavior

protected SwipeDismissBehavior<? extends View> getNewBehavior ()

Returns
SwipeDismissBehavior<? extends View>

getSnackbarBaseLayoutResId

protected int getSnackbarBaseLayoutResId ()

Returns
int

hasSnackbarStyleAttr

protected boolean hasSnackbarStyleAttr ()

Snackbars should still work with AppCompat themes, which don't specify a snackbarStyle. This method helps to check if a valid snackbarStyle is set within the current context, so that we know whether we can use the attribute.

Returns
boolean