How to disable copy/paste from/to EditText How to disable copy/paste from/to EditText android android

How to disable copy/paste from/to EditText


Best method is to use:

etUsername.setLongClickable(false);


If you are using API level 11 or above then you can stop copy,paste,cut and custom context menus from appearing by.

edittext.setCustomSelectionActionModeCallback(new ActionMode.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;            }        });

Returning false from onCreateActionMode(ActionMode, Menu) will prevent the action mode from being started(Select All, Cut, Copy and Paste actions).


You can do this by disabling the long press of the EditText

To implement it, just add the following line in the xml -

android:longClickable="false"