Toolbar, onCreateOptionsMenu () returns false, up does not work

I am using a new toolbar on Lollipop (no library support). My activity has a list, and if the list is empty, I don’t want to show the options menu. My implementation is as follows:

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 arrow works; when the method returns false, there is an arrow, but clicking on it does nothing. Is this some kind of Android bug?

+4
source share
1 answer

As work around, you can simply skip the ballooning menu as a whole and return true.

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    return true;
}

onCreateMenuItems(Menu menu) false, , . , : https://code.google.com/p/android/issues/detail?id=118700

+1

All Articles