How to trust disable Paste in Edittext

Viewed 30

I want hide option Paste when click double or Long Click Edittext enter image description here

I tried:

 edtSetName.customSelectionActionModeCallback = object : ActionMode.Callback {
        override fun onCreateActionMode(p0: ActionMode?, p1: Menu?): Boolean {
            return true
        }

        override fun onPrepareActionMode(p0: ActionMode?, menu: Menu?): Boolean {
            return false
      }

        override fun onActionItemClicked(p0: ActionMode?, p1: MenuItem?): Boolean {
            return false
        }

        override fun onDestroyActionMode(p0: ActionMode?) {}
    }

But that hide all option

1 Answers

I don't find a way to hide the menu popup, But you can disable it from pasting if the user taps on the menu

Create a custom EditText and override the onTextContextMenuItem method and return false for android.R.id.paste and android.R.id.pasteAsPlainText menu id's

@Override 
public boolean onTextContextMenuItem(int id) {
switch (id){
    case android.R.id.paste:
    case android.R.id.pasteAsPlainText:
        return false;

}
return super.onTextContextMenuItem(id);
}
Related