Skip to content Skip to sidebar Skip to footer

Dismiss The Contextual Action Bar When Nav. Drawer Is Toggled

The official page for the Navigation Drawer design pattern states: Sometimes the user will be in a state where a contextual action bar (CAB) appears instead of the app’s actio

Solution 1:

It is possible. You have to grab a reference to the ActionMode when it is created, and the ActionMode.Callback in your Activity:

@OverridepublicvoidonActionModeStarted(ActionMode mode) {
    super.onActionModeStarted(mode);
    mActionMode = mode;
}

@OverridepublicvoidonActionModeFinished(ActionMode mode) {
    super.onActionModeFinished(mode);
    mActionMode = null;
}

@OverridepublicActionModeonWindowStartingActionMode(ActionMode.Callback callback) {
    mActionModeCallback = callback;
    returnsuper.onWindowStartingActionMode(callback);
}

Then when your drawer opens/closes, finish the ActionMode or start a new ActionMode from the ActionMode.Callback:

@OverridepublicvoidonDrawerOpened(View drawerView) {
    if (mActionMode != null) {
        mActionMode.finish();
    }
}

@OverridepublicvoidonDrawerClosed(View drawerView) {
    if (mActionModeCallback != null) {
        startActionMode(mActionModeCallback);
    }
}

Post a Comment for "Dismiss The Contextual Action Bar When Nav. Drawer Is Toggled"