How to show Snackbar in android

How to show Snackbar in android
May 8, 2018 No Comments Android Development,Development Pushpendra Kumar

Another interesting component introduced in Material Design is the Snackbar. Snackbars are just like Toast messages except they provide action to interact with. Snackbar will be displayed at the bottom of the screen and can be swiped off in order to dismiss them.
This article explains about snackbar with few examples covering different scenarios.

    1. Simple Snackbar

Snackbar snackbar = Snackbar.make(this.findViewById(, message, Snackbar.LENGTH_LONG);;

    2. Action Snackbar

Snackbar.make(parentlayout, "This is main activity", Snackbar.LENGTH_LONG)
  .setAction("CLOSE", new View.OnClickListener() {
     public void onClick(View view) {
  .setActionTextColor(getResources().getColor(android.R.color.holo_red_light ))

    3. Customise Snackbar

Snackbar snack = Snackbar.make( (((Activity)context).findViewById(,message + "", Snackbar.LENGTH_SHORT);

snack.setDuration(Snackbar.LENGTH_INDEFINITE);//change Duration as you need
View view = snack.getView();
TextView tv = (TextView) view.findViewById(;
         tv.setTextColor(Color.WHITE);//change textColor
TextView tvAction = (TextView) view.findViewById(;

About The Author
Pushpendra Kumar I am passionate about mobile application development and professional developer at Colour Moon Technologies Pvt Ltd ( This website I have made so that I can meet with new challenges and can share here.

Leave a reply

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