Hide ActionBar MenuItems when Navigation Drawer sl

2019-01-31 07:26发布

I'm trying to implement a Navigation Drawer that hides the menu items in the ActionBar whenever the drawer is opened.

I am following google's documentation, however their code does not produce the expected behavior.

http://developer.android.com/training/implementing-navigation/nav-drawer.html

Using this code, the menu items are hidden when the drawer becomes completely opened , and shown when the drawer becomes completely closed.

However, the Gmail app behaves differently. The menu items are hidden as soon as the drawer opens by any amount. This is the behavior I want. Does anyone know how to achieve this?

Thanks!

7条回答
狗以群分
2楼-- · 2019-01-31 08:11

If you want to hide all menu items, simply use:

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    super.onPrepareOptionsMenu(menu);

    return showActionBarMenu; // boolean value, set it in drawer listeners as class variable
}

Then you do not need to visible of each menu item.

查看更多
登录 后发表回答