所以我正在尝试将自己的菜单项添加到Android上的文本选择上下文菜单中。然而,它显示出非常奇怪。这是它的样子:
这是我的代码:
etNote.setCustomSelectionActionModeCallback(new ActionMode.Callback() {
@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
menu.add(0, myItemId, 0, R.string.action_do);
return true;
}
@Override
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
return false;
}
@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
if (item.getItemId() == myItemId) {
int start = etNote.getSelectionStart();
int end = etNote.getSelectionEnd();
String selection = etNote.getText().toString().substring(start, end).trim();
if (!selection.isEmpty())
MyDialog.create(selection).show(getActivity().getSupportFragmentManager(),
TAG);
else Toast.makeText(getActivity().getApplicationContext(),
"Text Selection is Empty", Toast.LENGTH_SHORT).show();
return true;
}
return false;
}
如何让它看起来更好?