I'm trying to prevent the standard Contextual Action Bar from showing upon selecting text in an EditText, while keeping the text selection functionality. (Cause I want to use custom views to copy, cut and paste)
I've browsed the web, and tried the following things, with no luck, and don't know what to do now.
I tried overriding onLongClick() and returning false, which prevents the CAB from showing. but is also disables the text selection, so this is not a solution.
I tried setting setCustomSelectionActionModeCallback(null), which has no effect at all.
I tried setting setCustomSelectionActionModeCallback() with a custom ActionModeCallback, which contains the method onCreateActionMode(), in which I return false to "abort the mode", but this unfortunately also disables the text selection functionality.
I even tried extending EditText and overriding startActionMode() and pass null to the super, like below, but which just made it crash.
.
@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)