Disable CAB display in EditText text selection

I am trying to prevent the standard contextual action panel from displaying when selecting text in EditText, while maintaining the functionality of text selection. (Reason: I want to use custom views to copy, cut and paste)

I browsed the Internet and tried the following things, no luck, and don't know what to do now.

  • I tried to override onLongClick () and return false, which prevents the display of the CAB. but also disables text selection, so this is not a solution.

  • I tried to set setCustomSelectionActionModeCallback (null), which has no effect.

  • I tried to set setCustomSelectionActionModeCallback () using a special ActionModeCallback, which contains the onCreateActionMode () method, in which I return false to "interrupt mode", but this, unfortunately, also disables text selection functionality.

  • I even tried extending EditText and overriding startActionMode () and passing null to super, as shown below, but which just hit it.

.

@Override
public ActionMode startActionMode(ActionMode.Callback callback) {
    return super.startActionMode(null);
}

With the following error

 java.lang.NullPointerException
            at com.android.internal.policy.impl.PhoneWindow$DecorView$ActionModeCallbackWrapper.onCreateActionMode(PhoneWindow.java:3011)
            at com.android.internal.app.ActionBarImpl$ActionModeImpl.dispatchOnCreate(ActionBarImpl.java:909)
            at com.android.internal.app.ActionBarImpl.startActionMode(ActionBarImpl.java:453)
            at android.app.Activity.onWindowStartingActionMode(Activity.java:5005)
            at android.support.v7.app.ActionBarActivityDelegateICS$WindowCallbackWrapper.onWindowStartingActionMode(ActionBarActivityDelegateICS.java:349)
            at com.android.internal.policy.impl.PhoneWindow$DecorView.startActionMode(PhoneWindow.java:2636)
            at com.android.internal.policy.impl.PhoneWindow$DecorView.startActionModeForChild(PhoneWindow.java:2623)
            at android.view.ViewGroup.startActionModeForChild(ViewGroup.java:665)
            at android.view.ViewGroup.startActionModeForChild(ViewGroup.java:665)
            at android.view.ViewGroup.startActionModeForChild(ViewGroup.java:665)
            at android.view.ViewGroup.startActionModeForChild(ViewGroup.java:665)
            at android.view.ViewGroup.startActionModeForChild(ViewGroup.java:665)
            at android.view.ViewGroup.startActionModeForChild(ViewGroup.java:665)
            at android.view.ViewGroup.startActionModeForChild(ViewGroup.java:665)
            at android.view.ViewGroup.startActionModeForChild(ViewGroup.java:665)
            at android.view.ViewGroup.startActionModeForChild(ViewGroup.java:665)
            at android.view.ViewGroup.startActionModeForChild(ViewGroup.java:665)
            at android.view.View.startActionMode(View.java:4543)
            at com.harteg.homenotes.EditTextFormat.startActionMode(EditTextFormat.java:480)
            at android.widget.Editor.startSelectionActionMode(Editor.java:1551)
            at android.widget.Editor.performLongClick(Editor.java:859)
            at android.widget.TextView.performLongClick(TextView.java:8362)
            at android.view.View$CheckForLongPress.run(View.java:18425)
            at android.os.Handler.handleCallback(Handler.java:733)
            at android.os.Handler.dispatchMessage(Handler.java:95)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5081)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:607)
            at dalvik.system.NativeStart.main(Native Method)
+4
source share

Source: https://habr.com/ru/post/1544585/


All Articles