Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent Snackbar from closing?

I'm using a control, called Snackbar, from a 3rd party library - github.com/navasmdc/MaterialDesignLibrary.

The problem is that it is closing automatically, like a Toast.

What i am trying to do: It should stay until i click btn

Code snippet i am using

new SnackBar(ActSplash.this,       "Do you want change color of this button to red?",       "yes",         new View.OnClickListener() {           @Override           public void onClick(View v) {               ButtonFlat btn = (ButtonFlat) findViewById(R.id.buttonSnackBar);              //btn.setTextColor(Color.RED);         } }).show(); 

EDIT:

new SnackBar(ActSplash.this,                                 "Do you want change color of this button to red?",                                 "yes", new View.OnClickListener() {                              @Override                             public void onClick(View v) {                                 ButtonFlat btn = (ButtonFlat) findViewById(R.id.buttonSnackBar);                                 //btn.setTextColor(Color.RED);                             }                         }).setIndeterminate(true)                                 .show(); 

This shows a error cannot resolve show()


EDIT- FROM - NEW ANDROID DOCS

How to prevent android snackbar from closing

Snackbar                  .make(((ActMedicalRecordDetailNew)getActivity()).getMainContent(), R.string.snackBarNoNetConnectivity, Snackbar.LENGTH_LONG)                     .setAction(R.string.snackBarTryAgain, new View.OnClickListener() {                         @Override                         public void onClick(View view) {                             Intent intent = getActivity().getIntent();                             getActivity().finish();                             startActivity(intent);                         }                     })                     .show(); 
like image 596
Devrath Avatar asked Apr 28 '15 13:04

Devrath


People also ask

How do I stop snackbar in flutter?

You can hide the current SnackBar before the end of its duration by using: ScaffoldMessenger. of(ctx).

How do I get rid of snackbar?

OnClickListener() { @Override public void onClick(View v) { } }). show(); The snackbar can be dismissed by a swipe.

What is the use of snackbar in Android?

Snackbar in android is a new widget introduced with the Material Design library as a replacement of a Toast. Android Snackbar is light-weight widget and they are used to show messages in the bottom of the application with swiping enabled. Snackbar android widget may contain an optional action button.

How do you close a GETX snackbar in flutter?

Use Get. back() to close the snack bar.


2 Answers

Edit:

Snackbar is now part of the new Android Support Design library. you can use LENGTH_INDEFINITE as duration if you want to show it indefinitely. . You should drop the third party library you are using for it. Eg.

Snackbar.make(layout, R.string.snackBarNoNetConnectivity, Snackbar.LENGTH_INDEFINITE)     .show() 

Old answer

you have to call .setIndeterminate(true) before calling show()

final SnackBar tmp = new SnackBar(ActSplash.this,       "Do you want change color of this button to red?",       "yes",         new View.OnClickListener() {           @Override           public void onClick(View v) {               ButtonFlat btn = (ButtonFlat) findViewById(R.id.buttonSnackBar);              //btn.setTextColor(Color.RED);         } }); tmp.setIndeterminate(true); tmp.show(); 
like image 63
Blackbelt Avatar answered Oct 04 '22 09:10

Blackbelt


snackbar.setDuration(Snackbar.LENGTH_INDEFINITE); 
like image 41
Sreejith Kilmadi Avatar answered Oct 04 '22 08:10

Sreejith Kilmadi