Android棉花糖 - 文本选择菜单显示笨拙

时间:2018-03-21 10:19:22

标签: android contextmenu android-6.0-marshmallow menuitem textselection

所以我正在尝试将自己的菜单项添加到Android上的文本选择上下文菜单中。然而,它显示出非常奇怪。这是它的样子:

Text Selection Menu

这是我的代码:

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;
        }

如何让它看起来更好?

0 个答案:

没有答案