I can't disable copy paste option. on samsung galaxy S2, if i click on edittext, a arrow will come and on click on that arrow, all options are coming. onCreateContextMenu has not been called. within onUserInteration, I am just clearing clipboard info using setText() method, on emulator it is working, but not on real device. Please give me the idea. I am trying for hours, but unable to fix it.
Asked
Active
Viewed 3,067 times
4 Answers
0
See How to disable edittext in android
You can additionally set your edittext to android:editable="false"
-
Will work just fine, only I believe Saravana still want the user to be able to insert text by the on-screen keyboard. – Pieter888 Apr 26 '12 at 12:40
-
@Thomas K : Pieter is right. I want to disable only cut. copy and paste option. but editable – Santosh Apr 26 '12 at 13:50
0
Add this to for your edittext for which you want to disable copy paste option.
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;
}
});

Android
- 3,828
- 9
- 46
- 79
0
For disable Copy paste, You need to stop selection and then insertion. Use below code, its 100% working code.
//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);

Amar
- 87
- 7
-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);
-
1it's not worked. I already tried it. Because on device(galaxy s2), if you click, a cursor will be opened, if you click on the curosr then option will be opened in popup. In this scenario, this method will not be called. – Santosh Apr 26 '12 at 14:13