0

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.

DaveShaw
  • 52,123
  • 16
  • 112
  • 141
bonny
  • 13
  • 1
  • 3

2 Answers2

5

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

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

Susan Awiti
  • 341
  • 1
  • 2
  • 10