Tutorial by Examples

Creating a Snackbar can be done as follows: Snackbar.make(view, "Text to display", Snackbar.LENGTH_LONG).show(); The view is used to find a suitable parent to use to display the Snackbar. Typically this would be a CoordinatorLayout that you've defined in your XML, which enables adding ...
Function to customize snackbar public static Snackbar makeText(Context context, String message, int duration) { Activity activity = (Activity) context; View layout; Snackbar snackbar = Snackbar .make(activity.findViewById(android.R.id.content), message, d...
You can use Snackbar.Callback to listen if the snackbar was dismissed by user or timeout. Snackbar.make(getView(), "Hi snackbar!", Snackbar.LENGTH_LONG).setCallback( new Snackbar.Callback() { @Override public void onDismissed(Snackbar snackbar, int event)...
This example shows a white Snackbar with custom Undo icon. Snackbar customBar = Snackbar.make(view , "Text to be displayed", Snackbar.LENGTH_LONG); customBar.setAction("UNDO", new View.OnClickListener() { @Override public void onClick(View view) { //Put the logic...
Toasts are generally used when we want to display an information to the user regarding some action that has successfully (or not) happened and this action does not require the user to take any other action. Like when a message has been sent, for example: Toast.makeText(this, "Message Sent!&quo...
Creating an Snackbar without the need pass view to Snackbar, all layout create in android in android.R.id.content. public class CustomSnackBar { public static final int STATE_ERROR = 0; public static final int STATE_WARNING = 1; public static final int STATE_SUCCESS = 2; publi...

Page 1 of 1