1

enter image description hereI am using EditText in my Android application. When i long press on the EditText, i want to remove/hide all the default context menu like Copy,Cut,Select All etc. Only paste menu should be shown. I have tried with the solution in the below link, but along with Paste, SelectAll option is also showing. How can i remove it.

EditText: Disable Paste/Replace menu pop-up on Text Selection Handler click event

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115

1 Answers1

1
EditText yourEditText = (EditText) findViewById(R.id.your_edit_text);
yourEditText.setCustomSelectionActionModeCallback(new ActionMode.Callback() 
{
    @Override
    public boolean onCreateActionMode(ActionMode actionMode, Menu menu) 
    { 
        return false; 
    }
    @Override
    public boolean onPrepareActionMode(ActionMode actionMode, Menu menu) 
    { 
        return false; 
    }
    @Override
    public boolean onActionItemClicked(ActionMode actionMode, MenuItem menuItem) 
    { 
        return false; 
    }
    @Override
    public void onDestroyActionMode(ActionMode actionMode) 
    { 
        // Do your stuff here when you destroy
    }
    });
}

In your xml file, add following line to your respective editText:

android:textIsSelectable="false"

For further operations you can use that library:

https://github.com/neopixl/PixlUI

Muhammad Saad Rafique
  • 3,158
  • 1
  • 13
  • 21