Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you implement the snackbar that has the button at the bottom?

On the material design specs there is a snackbar that has the button at the bottom. How do you implement that?

Here is the image from the spec. I'm talking about the last one. enter image description here

like image 320
casolorz Avatar asked Jun 30 '17 09:06

casolorz


2 Answers

Android resizes the text of description automatically but it can not resize the text of ActionButton, so, if the text of button increases, Android will make that type of layout itself.

Here is the simple example ->

Snackbar snackbar = Snackbar
        .make(mainLayout, "Confirm delete?", Snackbar.LENGTH_LONG)
        .setAction("YES", new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Snackbar mSnackbar = Snackbar.make(mainLayout, "Message successfully deleted.", Snackbar.LENGTH_SHORT);
                mSnackbar.show();
            }
        });
 
snackbar.show();
like image 62
Mahesh Babariya Avatar answered Nov 19 '22 19:11

Mahesh Babariya


I've written a library that do just that. It also includes queue system. Try it out https://github.com/tingyik90/snackprogressbar.

It puts the action into next line if the button width is more than 25% of total width of the screen. You can modify my code by yourself if you need to. It is under SnackProgressBarLayout.java.

like image 2
tingyik90 Avatar answered Nov 19 '22 20:11

tingyik90