public class Snackbar extends BaseTransientBottomBar

Snackbars provide lightweight feedback about an operation. They show a brief message at the bottom of the screen on mobile and lower left on larger devices. Snackbars appear above all other elements on screen and only one can be displayed at a time.

Snackbars can contain an action which is set via setAction.

Snackbars automatically disappear after a timeout. They can also be dismissed by being swiped off screen, by action click, from a new snackbar being displayed, or manually via a call to dismiss.

To be notified when a snackbar has been shown or dismissed, you can provide a Callback via addCallback.

For more information, see the component developer guidance and design guidelines.

Summary

Protected methods

static boolean

hasSnackbarButtonStyleAttr(Context context)

This method is deprecated.

This is for backward compatibility with AppCompat themes.

Public methods

getDuration

public int getDuration()

Return the duration.

make

public static Snackbar make(View view, int resId, int duration)

Make a Snackbar to display a message.

Snackbar will try and find a parent view to hold Snackbar's view from the value given to view. Snackbar will walk up the view tree trying to find a suitable parent, which is defined as a CoordinatorLayout or the window decor's content view, whichever comes first.

Having a CoordinatorLayout in your view hierarchy allows Snackbar to enable certain features, such as swipe-to-dismiss and automatically moving of widgets.

Parameters
View view

The view to find a parent from.

int resId

The resource id of the string resource to use. Can be formatted text.

int duration

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

make

public static Snackbar make(View view, CharSequence text, int duration)

Make a Snackbar to display a message

Snackbar will try and find a parent view to hold Snackbar's view from the value given to view. Snackbar will walk up the view tree trying to find a suitable parent, which is defined as a CoordinatorLayout or the window decor's content view, whichever comes first.

Having a CoordinatorLayout in your view hierarchy allows Snackbar to enable certain features, such as swipe-to-dismiss and automatically moving of widgets.

make

public static Snackbar make(Context context, View view, CharSequence text, int duration)

Make a Snackbar to display a message

Snackbar will try and find a parent view to hold Snackbar's view from the value given to view. Snackbar will walk up the view tree trying to find a suitable parent, which is defined as a CoordinatorLayout or the window decor's content view, whichever comes first.

Having a CoordinatorLayout in your view hierarchy allows Snackbar to enable certain features, such as swipe-to-dismiss and automatically moving of widgets.

Parameters
Context context

The context to use to create the Snackbar view.

View view

The view to find a parent from. This view is also used to find the anchor view when calling setAnchorView.

CharSequence text

The text to show. Can be formatted text.

int duration

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

setAction

public Snackbar setAction(int resId, OnClickListener listener)

Set the action to be displayed in this BaseTransientBottomBar.

Parameters
int resId

String resource to display for the action

OnClickListener listener

callback to be invoked when the action is clicked

setBackgroundTintList

public Snackbar setBackgroundTintList(ColorStateList colorStateList)

Sets the tint color state list of the background Drawable.

setMaxInlineActionWidth

public Snackbar setMaxInlineActionWidth(int width)

Sets the max width of the action to be in the same line as the message. If the width is exceeded the action would go to the next line.

Protected methods

hasSnackbarButtonStyleAttr

protected static boolean hasSnackbarButtonStyleAttr(Context context)

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

Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.

Last updated 2025-10-28 UTC.