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();
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();