More on Material Design
Snackbars animate up from the bottom of the screen. After a certain period of time, or after another
interaction on the screen, they automatically animate back down. Snackbars are similar in purpose to
toasts, but unlike toasts they are a part of your app’s own interface. A toast appears above your app and
will stick around even if you navigate away. Also, snackbars let you provide a button so that the user
can take immediate action.
Like floating action buttons, Android provides an implementation of snackbars in the design support
library.
Snackbars are constructed and displayed in a similar way as Toasts:
Listing 35.11 Having a snack(bar)
Snackbar.make(container, R.string.munch, Snackbar.LENGTH_SHORT).show();
When constructing a Snackbar, pass in the view where the snackbar will be displayed, the text to
display, and the length of time that the snackbar should be visible for. Finally, call show() to display
the snackbar.
Snackbars can optionally provide an action on the right side. This is handy if the user performs a
destructive action, like deleting a crime, and you want to provide a way for the user to undo that action.
More on Material Design
In this chapter, we presented what amounts to a big grab bag of tools. Those tools are hardly any fun
if you let them sit and gather dust. So keep an eye out for ways to spiff up your application with some
depth or new animations.
One great place to look for inspiration is the material design specification itself, which is full of great
ideas: http://www.google.com/design/spec/material-design/introduction.html. You can also look in
the Google Play Store to see what other apps are doing and ask yourself, “How would I do that in my
own app?” You might end up with a niftier program than what you initially imagined.