What are the new features of Android Design Support Library and how to use its Snackbar?

The new Snackbar doesn’t require Android-M.

It is inside the new design support library and you can use it today.

Just update your SDK add this dependency in your code:

compile 'com.android.support:design:22.2.0'

You can use a code like this:

Snackbar.make(view, "Here's a Snackbar", Snackbar.LENGTH_LONG)
        .setAction("Action", null)
        .show();

It is like a Toast.

enter image description here

To assign an action you have to set the OnClickListener.

Snackbar.make(view, "Here's a Snackbar", Snackbar.LENGTH_LONG)
        .setAction("Action", myOnClickListener)
        .show();

If you would like to change the background color you can use something like this:

 Snackbar snackbar = Snackbar.make(view, "Here's a Snackbar",       
                   Snackbar.LENGTH_LONG);
 View snackBarView = snackbar.getView();
 snackBarView.setBackgroundColor(colorId);
 snackbar.show();

enter image description here

If you would like to have some built-in features as the swipe-to-dismiss gesture, or the FAB scrolling up the snackbar, simply having a CoordinatorLayout in your view hierarchy.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)