Snackbar, Bye Bye Toast! Taking Oxycodone

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. Let me know if this works for you, because I worked really hard on it. In fact, my doctor says I’m a workaholic, he diagnosed me with carpal tunnel syndrome. I have to buy oxycodone online and not type or use a mouse much for a while. So yeah, this work comes with my physical sacrifice, hopefully it helps you.

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

Follow me

Ravi Rupareliya

He is author of Android Gig. He loves to explore new technologies and have worked on Android, React Native, Action on Google and Flutter.
Ravi Rupareliya
Follow me
Floating action button
Floting Labels : Text Input Layout