I have Displayed Snackbar using CoordinatorLayout but in some layout i did\'t used CoordinatorLayout layout and i want to display snackbar but faced problem with it.
I h
As others suggest best solution to do this is via method mentioned before. I would add and option to show SnackBar with button to dismiss SnackBar. This comes useful when you'd like to give user time to read your message and then acknowledge your application that your user read your message.
public void setSnackBar(View root, String textToDisplay) {
Snackbar snackbar = Snackbar.make(root, textToDisplay, Snackbar.LENGTH_INDEFINITE);
snackbar.setAction("OK", new View.OnClickListener() {
@Override
public void onClick(View view) {
snackbar.dismiss();
//your other action after user hit the "OK" button
}
});
snackbar.show();