RE6
RE6

Reputation: 2724

Blocking EditText contextMenu

I want to create an EditText with the following changes:

  1. Clicking on it will not show the keyboard
  2. After SINGLE, SHORT click it will get into selection mode (When I say selection mode I mean the mode where you can select a section of the text (with two pointers). You can get to this mode by long clicking on the text.)
  3. After text is selected the copy/paste/cut toolbar will not be shown

For the first, I guess I can create an OnTouchListener and return true immediately, but then it will block me from doing the second thing (which I have no idea how to do).

I looked for a command that gets the EditText into selection mode, but all I could find was a way to get the selected text from it...

Thanks!

EDIT: I successfully made 1 and 2, but the toolbar still shows (tried unregisterForContextMenu)

Upvotes: 0

Views: 204

Answers (1)

Adem
Adem

Reputation: 9429

you can use edittex.setCustomSelectionActionModeCallback

setCustomSelectionActionModeCallback(new 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;
        }
    });

this will be block to open contextmenu for edittex

Upvotes: 0

Related Questions