0

I am building off of the NavigationDrawerFragment that can be auto-generated by Android Studio. It comes with functionality to show a global title and global menu (for the action bar) when the drawer is opened. It does this in an ActionBarDrawerToggle, using the @overriden methods onDrawerClosed and onDrawerOpened.

My question is, how can I make the context switch happen when the drawer first begins to open, rather than when it is completely open? I noticed that the gmail app does this.

theblang
  • 10,215
  • 9
  • 69
  • 120

1 Answers1

1

You can override DrawerLayout.DrawerListener.onDrawerStateChanged in your ActionBarToggle and make a call to Activity.invalidateOptionsMenu there. If you wanted to invalidate the menu more precisely you could compare the newState parameter to DrawerLayout.STATE_IDLE, DrawerLayout.STATE_DRAGGING, or DrawerLayout.STATE_SETTLING.

Similarly, you could also override DrawerLayout.DrawerListener.onDrawerSlide.

Then use DrawerLayout.isDrawerVisible rather than DrawerLayout.isDrawerOpen in Activity.onPrepareOptionsMenu.

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    final boolean drawerVisible = mDrawerLayout.isDrawerVisible(mDrawerList);
    menu.findItem(R.id.your_menu_item_id).setVisible(!drawerVisible);
    return super.onPrepareOptionsMenu(menu);
}
adneal
  • 30,484
  • 10
  • 122
  • 151