saulmm / CoordinatorBehaviorExample

2.71k stars 590 forks source link

Menu onOptionsItemSelected issue #44

Open yuanliu666 opened 6 years ago

yuanliu666 commented 6 years ago

For this example if you directly add onOptionsItemSelected it will not work. To solve this you need to add one line of code:

...
mToolbar.inflateMenu(R.menu.menu_main);
// add this line
setSupportActionBar(mToolbar);
...

And now it works! But the default title is annoying, so add another line to remove default title.

...
mToolbar.inflateMenu(R.menu.menu_main);
// add this line
setSupportActionBar(mToolbar);
setTitle("");
...

Cheers!

drinfernoo commented 6 years ago

This is something you should probably be doing anyways.