How to close an ActionMode menu programmatically on Honeycomb?
Whenever you are creating/starting ActionMode Create by
mMode = startActionMode(....);
To Dismiss it use following Syntax
if (mMode != null)
{
mMode.finish();
}
Kotlin code
Use ActionMode.Callback to finish ActionMode
after menu item pressed
private val actionModeCallbacks = object : ActionMode.Callback {
override fun onCreateActionMode(mode: ActionMode, menu: Menu): Boolean {
mode.menuInflater.inflate(R.menu.menu_action_mode, menu)
return true
}
override fun onPrepareActionMode(mode: ActionMode, menu: Menu): Boolean {
return false
}
override fun onActionItemClicked(mode: ActionMode, item: MenuItem): Boolean {
when (item.itemId) {
R.id.menu_item -> {
mode.finish() // after click of menu item close action mode
return true
}
}
return false
}
override fun onDestroyActionMode(mode: ActionMode) {
}
}
startSupportActionMode
(activity as AppCompatActivity).startSupportActionMode(actionModeCallbacks)
actionMode.finish();
When finish method is called from actionmode ...it will destroy the action mode.
@Override
public void onDestroyActionMode(ActionMode mode) {
//When action mode destroyed remove selected selections and set action mode to null
}
and destroy method is called from callback event