Snackbars provide lightweight feedback about an operation in a small popup at the base of the screen on mobile and at the lower left on desktop. They are above all over elements on screen, including the floating action button.
They automatically disappear after a timeout or after user interaction elsewhere on the screen, whichever comes first. Snackbars can be swiped off screen. They do not block input on the screens they appear on and cannot receive input focus. Show only one snackbar on screen at a time.Here are a couple of screenshots of how they should look:
Since there’s no native widget for this (at least not yet), I created a small Android library to quickly include this component on top of any activity. It only supports phones; it would still pop up at the base of the screen on tablets/desktops.
Using the Snackbar class is easy, this is how you would display it on an Activity:
However, I recommend you use the SnackbarManager to handle the Snackbars queue:
If you are using getApplicationContext() as the Context to create the Snackbar then you must
specify the target Activity when calling the SnackbarManager:
If you want an action button to be displayed, just assign a label and an ActionClickListener:
If you need to know when the Snackbar is shown or dismissed, assign a EventListener to it.
This is useful if you need to move other objects while the Snackbar is displayed. For instance,
you can move a Floating Action Button up while the Snackbar is on screen:
There are two Snackbar types: single-line (default) and multi-line (2 lines max). You can also set
the duration of the Snackbar similar to a
The lengths of a Snackbar duration are:
* LENGTH_SHORT: 2s
* LENGTH_LONG: 3.5s
* LENGTH_INDEFINTE: Indefinite; ideal for persistent errors
You could also set a custom duration.
Animation disabling is also possible.
You can also change the Snackbar’s colors.
Finally, you can attach the Snackbar to a AbsListView (ListView, GridView) or a RecyclerView.
NOTE: This has no effect on apps running on APIs < 11; swiping will always be disabled in those cases
The library project is on GitHub along with an example app. If you would like to add features to it or report any bugs, refer to the issues section.
Here are a few screenshots of the library in action: