It is possible. You have to grab a reference to the ActionMode
when it is created, and the ActionMode.Callback
in your Activity
:
@Override
public void onActionModeStarted(ActionMode mode) {
super.onActionModeStarted(mode);
mActionMode = mode;
}
@Override
public void onActionModeFinished(ActionMode mode) {
super.onActionModeFinished(mode);
mActionMode = null;
}
@Override
public ActionMode onWindowStartingActionMode(ActionMode.Callback callback) {
mActionModeCallback = callback;
return super.onWindowStartingActionMode(callback);
}
Then when your drawer opens/closes, finish the ActionMode
or start a new ActionMode
from the ActionMode.Callback
:
@Override
public void onDrawerOpened(View drawerView) {
if (mActionMode != null) {
mActionMode.finish();
}
}
@Override
public void onDrawerClosed(View drawerView) {
if (mActionModeCallback != null) {
startActionMode(mActionModeCallback);
}
}