删除TextView选择ActionMode中的默认CAB项

时间:2015-11-08 18:54:57

标签: android textview android-actionmode

我试图删除默认项目,例如"复制"当用户从 TextView 元素中选择一些文本时,从CAB中选择全部"

我已使用此代码覆盖默认操作,但为新菜单资源充气并不会删除默认项目。

textView.setCustomSelectionActionModeCallback(new ActionMode.Callback() {
    @Override
    public boolean onCreateActionMode(ActionMode mode, Menu menu) {

        mode.setTitle("Test");
        mode.getMenuInflater().inflate(R.menu.new_menu_selection, menu);
        return true;
    }

    @Override
    public boolean onPrepareActionMode(ActionMode mode, Menu menu) {

        return false;
    }

    @Override
    public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
        return false;
    }

    @Override
    public void onDestroyActionMode(ActionMode mode) {

    }
});

有解决方法吗?

1 个答案:

答案 0 :(得分:2)

要删除默认项目,您可以在充气新菜单之前调用menu.clear()

textView.setCustomSelectionActionModeCallback(new ActionMode.Callback() {
    @Override
    public boolean onCreateActionMode(ActionMode mode, Menu menu) {

        menu.clear();

        mode.setTitle("Test");
        mode.getMenuInflater().inflate(R.menu.new_menu_selection, menu);
        return true;
    }

    @Override
    public boolean onPrepareActionMode(ActionMode mode, Menu menu) {

        return false;
    }

    @Override
    public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
        return false;
    }

    @Override
    public void onDestroyActionMode(ActionMode mode) {

    }
});