if you want to get custom contextual action mode on text selection, then you can do somehing like this
ed = (TextView) findViewById(R.id.txtview);
ed.setText("Hello World! Let's select some text!!");
initActionModeCallbacks();
ed.setTextIsSelectable(true);
ed.setCustomSelectionActionModeCallback(mActionModeCallback);
ed.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
Log.v(this.toString(), "Long click.");
ed.setCursorVisible(true);
v.setSelected(true);
return false;
}
});
and in onCreateActionMode(ActionMode mode, Menu menu), if you want to remove standard selection items, you can call
menu.clear();
also note, items in your menu needs to have SHOW_AS_ACTION_ALWAYS flag, because overflow button is not working cause focus change https://stackoverflow.com/a/9883763/2751697