Snackbar Android widget example

Snackbar Android is introduced in Android material design. Its work same as Toast widget to show short time Message or Feedback. But Snackbar also provides control on some action (Like Undo, Retry, Cancel etc). You can also change the color of Snackbar and text. This message show in bottom of your app like below image.


Snackbar Android widget example

In this tutorial, you will learn how to use Snackbar in the Android app with an example.

How to use Android Snackbar :

Create a new Android project (How to create a new project)

Step 1. Add library in gradle:app (ProjectName>app>build.gradle(app))

Android design library 24.2.0 (version always changing by the Android team so always update Android SDK and Tools)

The complete code for adding a dependency in build.gradle


Step 2. Add following code in app>src>main>res>layout>”activity_main.xml”

CoordinatorLayout is acting as a container of performing child view action.


Step 3. Add following code in app>src>main>java>””

Performing an action on the button to open a snackbar, with onclicklisteners and showing a message in toast a confirmation.


Step 4. Run the application, in the emulator or On your Android device

Output Snackbar Android example Screenshot


Snackbar Android widget example

Snackbar Android example Source code link


Development environment

Android Studio : 2.1.3
compileSdkVersion 24
buildToolsVersion “24.0.1”
minSdkVersion 15 (Ice Cream Sandwich)
targetSdkVersion 24 (Nougat)

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.