I'm using the new Toolbar on Lollipop (no support library). My activity has a list and if the list is empty, I don't want to show any options menu. My implementation looks like this:
in onCreate():
setActionBar((Toolbar) findViewById(R.id.toolbar));
getActionBar().setDisplayHomeAsUpEnabled(true);
And the menu method:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
if (tasks.isEmpty()) {
return false;
}
getMenuInflater().inflate(R.menu.menu_tasks, menu);
return true;
}
When the method inflates the menu and returns true, the 'up' navigation arrow works file; when the method returns false, the arrow is there, but clicking it doesn't do any thing. Is this some kind of an Android bug?
As a work around you can just skip inflating the menu altogether and return true.
@Override
public boolean onCreateOptionsMenu(Menu menu) {
return true;
}
That being said, the documentation for onCreateMenuItems(Menu menu)
suggests returning false as you initially tried to do should work. There is a bug tracking this issue right now: https://code.google.com/p/android/issues/detail?id=118700
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With