Skip to content Skip to sidebar Skip to footer

Hiding Contexual Action Bar While Navigation Drawer Is Open

The question is similar to this except for the fact that instead of using a View Pager (VP) I want to use a Navigation Drawer (ND). I have a list of elements that activates a Conte

Solution 1:

To achieve this requirement, I am calling these two methods from the ActionBarDrawerToggle callback methods:

publicvoidonDrawerOpened() {
  if (mActionMode != null) {
    mCheckedListItems = mListView.getCheckedItemPositions().clone();
    mActionMode.finish();
  }
}
publicvoidonDrawerClosed() {
  if (mCheckedListItems!=null) {
    for (int i=0; i<mCheckedListItems.size(); i++) {
      if (mCheckedListItems.valueAt(i)) {
        mListView.setItemChecked(mCheckedListItems.keyAt(i), true);
      }
    }
  }
  mCheckedListItems = null;
}

Solution 2:

If you're using a material design styled navigation drawer, the accepted solution doesn't look all that nice as the ActionMode sits on top of the drawer until it's fully open.

An alternative is to use onDrawerStateChanged instead, then as soon as you start dragging the drawer it will hide the ActionMode:

@OverridepublicvoidonDrawerStateChanged(int newState) {
    super.onDrawerStateChanged(newState);
    mActionMode.finish();
}

Solution 3:

The Sprockets library (disclosure: I'm the developer) does this automatically when extending NavigationDrawerActivity and SprocketsListFragment. Instead of the latter, it's also possible to extend SprocketsFragment and provide your AbsListView in getAbsListView(). When the navigation drawer is opened, the ActionMode will be hidden. And when it is closed, the ActionMode will be restored.

Post a Comment for "Hiding Contexual Action Bar While Navigation Drawer Is Open"