Home Coding Android Coding How to Create a Simple Snackbar in Android

How to Create a Simple Snackbar in Android



Introduced in Material Design, SnackBars are similar to Toast messages but have an additional action for the user to interact with. A SnackBar appears at the bottom of the  screen and has to be swiped off in order to be dismissed.

Setting the CoordinatorLayout as a view parameter enables swipe-to-dismiss and automatically moves widgets.

The duration of a Snackbar can be set using


Let’s see a practical example of the Snackbar in action by creating a simple app.

How to Create a SnackBar App in Android Studio

1. Create a New Android Studio Project, choose an empty activity and leave the default activity name.

2. Open build.gradle and insert the following dependencies.

3. Insert the following code into activity_main.xml.

4.  Make the following changes into MainActivity.java:

5. Start the app, it should look like this:

Denis Madroane App junkie, Android developer, proud Freelancer. Passionate about app development and blogging, updated with the new stuff. Likes to think that he's versed in app re-skinning, content writing and social media.


Your email address will not be published. Required fields are marked *

Powered by WordPress