BaseTransientBottomBar

public abstract class BaseTransientBottomBar<B extends BaseTransientBottomBar<B>>

Known direct subclasses
Snackbar

Snackbars provide lightweight feedback about an operation.


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

Parameters
<B extends BaseTransientBottomBar<B>>

The transient bottom bar subclass.

Summary

Nested types

public abstract class BaseTransientBottomBar.BaseCallback<B>

Base class for BaseTransientBottomBar callbacks.

Behavior for BaseTransientBottomBar.

This interface is deprecated.

Use com.google.android.material.snackbar.ContentViewCallback instead.

Constants

static final int

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

static final int

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

static final int

Show the Snackbar indefinitely.

static final int

Show the Snackbar for a long period of time.

static final int

Show the Snackbar for a short period of time.

Public fields

BaseTransientBottomBar.Behavior
final Context
int

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

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

void

Dismiss the BaseTransientBottomBar.

View

Returns the anchor view for this BaseTransientBottomBar.

int

Returns the animation mode.

BaseTransientBottomBar.Behavior

Return the behavior.

Context

Returns the BaseTransientBottomBar's context.

int

Return the duration.

View

Returns the BaseTransientBottomBar's view.

boolean

Returns whether the anchor view layout listener is enabled.

boolean

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

boolean

Return whether this BaseTransientBottomBar is currently being shown.

boolean

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

B

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

Sets the BaseTransientBottomBar.Behavior to be used in this .

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 the BaseTransientBottomBar.

Protected methods

void
dispatchDismiss(int event)
SwipeDismissBehavior<View>
int
boolean

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

Constants

ANIMATION_MODE_FADE

public static final int ANIMATION_MODE_FADE = 1

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

ANIMATION_MODE_SLIDE

public static final int ANIMATION_MODE_SLIDE = 0

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

LENGTH_INDEFINITE

public static final int LENGTH_INDEFINITE = -2

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
setDuration

LENGTH_LONG

public static final int LENGTH_LONG = 0

Show the Snackbar for a long period of time.

See also
setDuration

LENGTH_SHORT

public static final int LENGTH_SHORT = -1

Show the Snackbar for a short period of time.

See also
setDuration

Public fields

context

public final Context context

duration

public int duration

Protected fields

Protected constructors

BaseTransientBottomBar

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

Constructor for the transient bottom bar.

Uses Context from parent.

Parameters
ViewGroup parent

The parent for this transient bottom bar.

View content

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
)

Public methods

addCallback

public B addCallback(BaseTransientBottomBar.BaseCallback<B> callback)

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

Parameters
BaseTransientBottomBar.BaseCallback<B> callback

Callback to notify when transient bottom bar events occur.

See also
removeCallback

dismiss

public void dismiss()

Dismiss the BaseTransientBottomBar.

getAnchorView

public View getAnchorView()

Returns the anchor view for this BaseTransientBottomBar.

See also
setAnchorView

getAnimationMode

public int getAnimationMode()

Returns the animation mode.

See also
setAnimationMode

getBehavior

public BaseTransientBottomBar.Behavior getBehavior()

Return the behavior.

See also
setBehavior

getContext

public Context getContext()

Returns the BaseTransientBottomBar's context.

getDuration

public int getDuration()

Return the duration.

See also
setDuration

getView

public View getView()

Returns the BaseTransientBottomBar's view.

isAnchorViewLayoutListenerEnabled

public boolean isAnchorViewLayoutListenerEnabled()

Returns whether the anchor view layout listener is enabled.

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.

isShown

public boolean isShown()

Return whether this BaseTransientBottomBar is currently being shown.

isShownOrQueued

public boolean isShownOrQueued()

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

removeCallback

public B removeCallback(BaseTransientBottomBar.BaseCallback<B> callback)

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

Parameters
BaseTransientBottomBar.BaseCallback<B> callback

Callback to remove from being notified of transient bottom bar events

See also
addCallback

setAnchorView

public B setAnchorView(int anchorViewId)

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

Throws
java.lang.IllegalArgumentException

if the anchor view is not found.

setAnchorView

public B setAnchorView(View anchorView)

Sets the view the BaseTransientBottomBar should be anchored above.

setAnchorViewLayoutListenerEnabled

public void setAnchorViewLayoutListenerEnabled(
    boolean anchorViewLayoutListenerEnabled
)

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

setAnimationMode

public B setAnimationMode(int animationMode)

Sets the animation mode.

Parameters
int animationMode

of ANIMATION_MODE_SLIDE or ANIMATION_MODE_FADE.

See also
getAnimationMode

setBehavior

public B setBehavior(BaseTransientBottomBar.Behavior behavior)

Sets the BaseTransientBottomBar.Behavior to be used in this .

setDuration

public B setDuration(int duration)

Set how long to show the view for.

Parameters
int duration

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

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.

show

public void show()

Show the BaseTransientBottomBar.

Protected methods

dispatchDismiss

protected void dispatchDismiss(int event)

getNewBehavior

protected SwipeDismissBehavior<View> getNewBehavior()

getSnackbarBaseLayoutResId

protected int getSnackbarBaseLayoutResId()

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.