2

我无法禁用复制粘贴选项。在三星galaxy S2上,如果我点击edittext,会出现一个箭头,点击那个箭头,所有选项都会出现。onCreateContextMenu 尚未被调用。在 onUserInteration 中,我只是使用 setText() 方法清除剪贴板信息,在模拟器上它正在工作,但在真实设备上却没有。请给我这个想法。我尝试了几个小时,但无法修复它。

4

4 回答 4

0

See How to disable edittext in android

You can additionally set your edittext to android:editable="false"

于 2012-04-26T12:37:11.103 回答
0

将此添加到您要禁用复制粘贴选项的edittext。

  edittext.setCustomSelectionActionModeCallback(new Callback() {

                public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
                    return false;
                }

                public void onDestroyActionMode(ActionMode mode) {                  
                }

                public boolean onCreateActionMode(ActionMode mode, Menu menu) {
                    return false;
                }

                public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
                    return false;
                }
            });
于 2012-12-20T12:01:18.220 回答
0

要禁用复制粘贴,您需要停止选择然后插入。使用下面的代码,它的 100% 工作代码。

   //This disable the paste 
    editText.setCustomInsertionActionModeCallback(new ActionMode.Callback() {
        @Override
        public boolean onCreateActionMode(ActionMode mode, Menu menu) {
            menu.clear();
            return false;
        }

        @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) {

        }
    });

    //This Disable selection of text
    editText.setCustomSelectionActionModeCallback(new Callback() {
        @Override
        public boolean onCreateActionMode(ActionMode mode, Menu menu) {
            menu.clear();
            return false;
        }

        @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) {

        }
    });
    editText.setLongClickable(false);
    editText.setTextIsSelectable(false);
于 2020-08-06T11:19:06.207 回答
-2

You might want to check out this question here.

Apparently by catching the long touch event you can prevent the copy paste tools from activating like this:

OnLongClickListener mOnLongClickListener = new OnLongClickListener() 
{
    @Override
    public boolean onLongClick(View v) 
    {
        // prevent context menu from being popped up, so that user
        // cannot copy/paste from/into any EditText fields.
        return true;
    }
};

Then set the onLongClickListener you just created on the EditText like this:

myEditTextView.setOnLongClickListener(mOnLongClickListener);
于 2012-04-26T12:37:17.580 回答