Course Content

Course Content

Snackbar Example

How To Create Snackbar Android

Now we will see by taking practical Snakbar Android example that how we can create Snackbar in Android, for that we will first create a project named 'SnackBarExample'.

First of all we will open 'activity_main.xml' file from layout folder, and here we will generate Coordinator layout,





After that, we will provide basic properties like height, width, padding for content.

After that we create a Button and specify all the properties of it,



android:text='Show Snackbar""


android:layout_height=""wrap_parent""   />


Now we will design the main file which is in 'java' folder, ie. '' file, now the file is default generated, but we will see that how we can use the Snackbar android concept here. We have directly passed MainActivity and implemented that to OnClickListener.

We will do view identification for our button and snackbar here,




Now we will add Click Listener,



After that, we will create a method in which we will generate code to show Snackbar Android,

private void ShowSnackbar()


Snackbar snackbar=Snackbar.make(coordinatorLayout,"" "",Snackbar.LENGTH_LONG);


Now we will set the action of Snackbar,

snackbar.setAction(""Show Another"", new View.onClickListener()



public void onClick(View v)


Snackbar s=Snackbar.make(coordinatorLayout,""Another Snackbar"",Snackbar.LENGTH_LONG);;




Now we will specify the properties of how Snackbar android should be displayed,


View view=snackbar.getView();

TextView textView=(TextView)view.findViewById(;



public void onClick(View v)




 Now we will execute the program, on executing our program is successfully running.


Recommended Courses

Share With Friend

Have a friend to whom you would want to share this course?

Download LearnVern App

App Preview Image
App QR Code Image
Code Scan or Download the app
Google Play Store
297K+ Downloads
App Download Section Circle 1
4.5 Rating
App Download Section Circle 2
10K+ Reviews
App Download Section Circle 3
  • Learn anywhere on the go
  • Get regular updates about your enrolled or new courses
  • Share content with your friends
  • Evaluate your progress through practice tests
  • No internet connection needed
  • Enroll for the webinar and join at the time of the webinar from anywhere