How to make customizable Snackbar in android

Updated 29 October 2021


In this blog,

We ‘ll discuss the UX concept which is introduced in Android 5.0 material design called Snackbar. Which is inspired from the Toast widget of android.

You can call it as a toast message with an action button. SnackBar will be displayed at the bottom or bottom left for a larger device It can be swiped off in order to dismiss them if passing CoordinatorLayout as view param of SnackBar.

How to make simple Snackbar

Below is the syntax of a simple snackbar.

The make function accepts three parameters. View, display message and duration of the message to be displayed.

View: Find a parent view to hold Snackbar’s view from the value given to view(in this case our coordinatorLayout).

The duration should be LENGTH_SHORT, LENGTH_LONG or LENGTH_INDEFINITE. When LENGTH_INDEFINITE is used, the snackbar will be displayed indefinite time and can be dismissed with swipe off.

And you can set the duration of your snackbar by setDuration(int) method.

How to make Snackbar with Action Callback

We can also set a callback interaction method using setAction() method.

In above example, There is a snackbar with retry action callback method.

How to make our custom Snackbar

Snackbar’s default text color is white and in android 5.0 or above it takes the primary color automaticlly. And #323232 background color. But we can customize that things.

In above example, We set the actionbar color to GREEN and text color to BLUE.

. . .

Leave a Comment

Your email address will not be published. Required fields are marked*

Be the first to comment.

Start a Project

    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home