2

I have an EditText, and when I perform a long click, the word being pressed is selected, and two other things happen.

First, a contextual action bar appears at the top of the app, with icons for copy, cut, paste, replace, select all.

Second, another context menu appear around the word, like option bubbles, with things like "paste" and "replace". I'm not sure if these bubbles are device specific (e.g. Samsung / Nexus7).

These bubbles do the exact same thing as the action bar, and are really cluttering up the screen with softkeyboard open as well.... Is there any way I can disable the bubbles, while keeping the action bar at the top?

I noticed that the "super" function in performLongClick is a parent function to both these calls. If you block it, neither will occur. But I haven't found any overrides yet that would let me pick one and not the other.

edit: both context menus will also occur if you perform a double tap.

public class MyExtendedEditText extends EditText {
.... 
@Override
public boolean performLongClick() {

//Super function selects word (otherwise a=b), and calls action bar,
//and text selection bubbles

boolean retval =super.performLongClick();

    int a = getSelectionStart();
    int b = getSelectionEnd();

    Log.i("System.out", "long click " + a + "  " +  b);


    return retval;
}
NameSpace
  • 10,009
  • 3
  • 39
  • 40

1 Answers1

0

The 'contextual action bar' that appears at the top of the app, with icons for copy, cut, paste, replace, select all can be disabled by following the examples shown in these solutions:

As for the 'option bubbles' (as per the image below), this appears when the text selection handles are clicked and there's text in the clipboard, or some text to be replaced:

Text selection handle with paste menu

In order to disable this, it's necessary to prevent the PASTE/REPLACE menu from appearing in the show() method of the (non-documented) android.widget.Editor class. Before the menu appears, a check is done to if (!canPaste && !canSuggest) return;. The two methods that are used as the basis to set these variables are both in the EditText class:

A more complete answer, with an example override of the EditText class, and incorporation of all solutions listed, is available here.

Community
  • 1
  • 1
CJBS
  • 15,147
  • 6
  • 86
  • 135