Snackbar, Bye Bye Toast!

In previous post we talked about FloatingActionButton, its usage and some attributes.

Today we will talk about Snackbar

Snackbar provide lightweight feedback at the bottom of screen.

Snackbar is simply replacement of Toast in Material Design Library. Here are some of characteristics of Snackbar :

  • It can contain action and it is optional.
  • It appears above most elements on the screen.
  • It animate from bottom of screen.
  • It should contain very short string/message.
  • Only one Snackbar can be displayed at a time same as Toast.

Syntax : 

Attributes : 

  1. view = first parameter is ‘view’, it can be parent view to hold snackbar.
  2. message = second parameter is ‘message’, it can be a simple string which can be displayed in snackbar.
  3. duration = third parameter is ‘duration’ which will be same as Toast (LENGHT_SHORT or LENGTH_LONG).

Methods : 

  1. make() = to make snackbar.
  2. setAction() = to set an action.
  3. show() = to show a snackbar.

Add design support library in gradle file.

compile ‘com.android.support:design:22.2.0’

Example : 

root is root layout or parent layout.

Output : 

snackbar

Floating action button
Floting Labels : Text Input Layout