To prevent an EditText from receiving content from the clipboard, I disable the long click and text selectable, plus cleared the action mode menu:
EditText editText = findViewById(R.id.et);
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;
}
});
editText.setTextIsSelectable(false);
editText.setLongClickable(false);
The problem is that I keep receiving clipboard suggestions that when selected are pasted to my EditText. How can I disable this or simply ignore this pasted content?
To disable all types of copy past from keyboard, keyboard extension, Action Menu and any other type you can add a textChangeListener to your EditText and check in the method
beforeTextChangedlike the follow:this solution works if someone past more than one character at the time. Good luck