我认为您正在寻找的是TextView.setCustomSelectionActionModeCallback.这将允许您在选择文本时创建自己的ActionMode.Callback.然后,您可以使用TextView.getSelectionStart和TextView.getSelectionEnd在选择MenuItem时检索所选文本.这是一个简单的例子:
mTextView.setCustomSelectionActionModeCallback(new Callback() {
@Override
public boolean onPrepareActionMode(ActionMode mode,Menu menu) {
// Remove the "select all" option
menu.removeItem(android.R.id.selectAll);
// Remove the "cut" option
menu.removeItem(android.R.id.cut);
// Remove the "copy all" option
menu.removeItem(android.R.id.copy);
return true;
}
@Override
public boolean onCreateActionMode(ActionMode mode,Menu menu) {
// Called when action mode is first created. The menu supplied
// will be used to generate action buttons for the action mode
// Here is an exampl