A snackbar is an improved version of android toast. A snackbar is much better and flexible compared to android toast. Unlike toast on a snackbar you can add a button to represent action. Even custom snackbar can be made according to your preferences. In this guide let’s make the default and material version of snackbar.

Where to use Snackbar ?

So, snackbar is used when you wanted to show not so important messages in your application. Something like “Saved as a draft” in email application.

The other reason to use snackbar is that it doesn’t interrupt user flow but just informs the user.

It’s an improvement for default Toast with better looks and flexibility. Even official document suggests to use snackbar as a toast replacement.

One Line Snackbar

We can make snackbar in a single line. one-line

Also unlike toast, snackbar has three time params [LENGTH_SHORT, LENGTH_LONG, LENGTH_INDEFINITE]

Pass a view

To show snackbar in a desired view. view-passing

This way snackbar will be drawn on the nearby decor view on the view passed. Usually it is recommended to use co-ordinator layout as the parent, but not mandatory.

Anchor a view to snackbar

For instance, you have a floating action button in your app layout and you don’t want it to be hidden when the snackbar is shown. Adding the floating action button as achor for the snackbar. This will make floating action button to move above the snackbar.


S Add button to snackbar

To add action button to the snackbar follow the below step.


So in the end, snackbar is excellent component to show non-important messages to the user and a preffered replacement for android toast.