I am quite new to Android developing area and recently I hv encountered a tough problem.
I was trying to make a Edittext which should NOT ALLOW user to copy content from or paste content to it. I hv googled a lot and find there seems to be 2 popular ways of doing so:
1st way, to set it in the layout file:
android:longClickable="false"
2nd way, to programmatically set it:
myEdittext.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;
}
});
But I just found that whichever way I chose, the edittext area could only be disabled from long clickable, which then prevents user from accessing the "select all, copy and paste" menu through long clicking. But both the 2 solution DID NOT prevent the user from accessing the "paste" function through just a simple tap on the cursor.
So my question is: how could I TOTALLY block user from copy and paste function in a certain Edittext. Is anyone help? Thx a lot
the solution is very simple
sample preview
There is one possibility, by disabling the cursor handler. You won't get the paste button, but you will also not be able to move the cursor with touch.
best programmatically way is:
Or, just in xml
You can totally hide "select all, copy and paste" menu and also "paste" function which pop up when simple tap on the cursor.
For that you have to create a custom EditText class. Here is an example...
Use this EditText in your layout. Now, it will not show any copy/paste menu. It will show only blue handle but when you click on that you will not get any pop up of paste option.
Hope this helps...