How to disable copy/paste from/to EditText

后端 未结 24 1663
情歌与酒
情歌与酒 2020-11-22 12:18

In my application, there is a registration screen, where i do not want the user to be able to copy/paste text into the EditText field. I have set an onLon

24条回答
  •  自闭症患者
    2020-11-22 12:55

    I am able to disable copy-and-paste functionality with the following:

    textField.setCustomSelectionActionModeCallback(new ActionMode.Callback() {
    
        public boolean onCreateActionMode(ActionMode actionMode, Menu menu) {
            return false;
        }
    
        public boolean onPrepareActionMode(ActionMode actionMode, Menu menu) {
            return false;
        }
    
        public boolean onActionItemClicked(ActionMode actionMode, MenuItem item) {
            return false;
        }
    
        public void onDestroyActionMode(ActionMode actionMode) {
        }
    });
    
    textField.setLongClickable(false);
    textField.setTextIsSelectable(false);
    

    Hope it works for you ;-)

提交回复
热议问题