我使用了Google的指南和本教程来制作自己的上下文操作栏。
private ActionMode.Callback mActionModeCallback = new ActionMode.Callback() {
// Called when the action mode is created; startActionMode() was called
@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
// Inflate a menu resource providing context menu items
MenuInflater inflater = mode.getMenuInflater();
inflater.inflate(R.menu.annotation_menu, menu);
return true;
}
// Called each time the action mode is shown.
// Always called after onCreateActionMode, but
// may be called multiple times if the mode is invalidated.
@Override
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
return false; // Return false if nothing is done
}
// Called when the user selects a contextual menu item
@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
switch (item.getItemId()) {
case R.id.custom_button:
// do some stuff
break;
case R.id.custom_button2:
// do some other stuff
break;
default:
// This essentially acts as a catch statement
// If none of the other cases are true, return false
// because the action was not handled
return false;
}
finish(); // An action was handled, so close the CAB
return true;
}
// Called when the user exits the action mode
@Override
public void onDestroyActionMode(ActionMode mode) {
mActionMode = null;
}
};
此菜单旨在在用户选择文本时显示,因此它会覆盖本机复制/粘贴菜单。现在我要解决我的问题。
因为我要覆盖用于文本选择的功能,所以我还向中添加了LongClickListenera WebView并实现了该onLongClick(View v)方法,以便可以检测用户何时进行选择。
长按时,我看到我的自定义菜单出现,但是没有突出显示文本。
我需要文本选择功能;没有它,我的菜单毫无意义。
如何覆盖onLongClick(View v),但保持Android提供的文本选择?
如果无法实现,我可以打到startActionMode(mActionModeCallback)其他地方以便正常选择文本,但是我的自定义菜单也会出现吗?
如果这些都不可行,请帮助。
杨魅力
狐的传说
相关分类