Disabling contextual menu when long clicking text in EditText

811 views Asked by At

I want to disable the default Contextual ActionBar (containing the Copy-Paste-Select All items) when long clicking a word in an EditText. This bar:

enter image description here

I tried to use the following code, but the problem with this code is that the selection handles don't appear anymore:

editText.setCustomSelectionActionModeCallback(new Callback() {
      @Override
      public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
        return false;
      }

      @Override
      public void onDestroyActionMode(ActionMode mode) {        
      }

      @Override
      public boolean onCreateActionMode(ActionMode mode, Menu menu) {
        // I also tried menu.clear() but has the same behavior.
        return false;
      }

      @Override
      public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
        return true;
      }
    });

Does any one know how to disable the contextual actionbar and keep the selection handles?

1

There are 1 answers

0
Omar On BEST ANSWER

After long hours of research, unfortunately the only way to do this is by forking TextView & EditText code and changing its code directly.