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
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();
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()
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();
You can hide the current SnackBar before the end of its duration by using: ScaffoldMessenger. of(ctx).
OnClickListener() { @Override public void onClick(View v) { } }). show(); The snackbar can be dismissed by a swipe.
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.
Use Get. back() to close the snack bar.
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();
snackbar.setDuration(Snackbar.LENGTH_INDEFINITE);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With