Reputation: 13
How to make the start Snackbar message when you click on the menu?
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case (R.id.reset):
number1.setText(null);
number2.setText(null);
//Snackbar.make(findViewById(android.R.id.content) , "Text", Snackbar.LENGTH_SHORT).setAction("Action", null).show();
break;
case (R.id.quit):
finish();
break;
}
return super.onOptionsItemSelected(item);
}
It does not react.
Upvotes: 0
Views: 1094
Reputation: 341
When you click on menu item you can do like this:
Snackbar.make(getWindow().getDecorView(), .....);
Remember you MUST pass View
object in order to show snackbar
Upvotes: 0
Reputation: 191
You can use the main activity view to display the SnackBar :
Snackbar.make(this.findViewById(android.R.id.content),
"FooBar", Snackbar.LENGTH_LONG).setAction("Action", null).show();
Upvotes: 5