How to disable long-click which opens the Android top menu bar with copy/paste/etc. buttons in Cordova Crosswalk apps?

此生再无相见时 提交于 2019-12-12 02:53:11

问题


As the title says, I have a Cordova application which has the Cordova Crosswalk plugin installed and runs on Android and iOS.

Specifically on Android, and at least on versions Android 5.1.1 and 4.4.4 (and likely on all of them due to Crosswalk), whenever I long-press on an input field, my WebView shrinks in height and shows a weirdly-styled top bar with cut/copy/paste/clipboard buttons, and a "back" button which closes the top bar:

How do I prevent this long-click? I have tried adding an onLongClickListener and calling setLongClickable(false) on the WebView in my app's MainActivity.java, as follows:

public class MainActivity extends CordovaActivity {
    private static final String TAG = MainActivity.class.getSimpleName();

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // Set by <content src="index.html" /> in config.xml
        loadUrl(launchUrl);

        // disable the context menu and all long clicks
        super.getView().setOnLongClickListener(new View.OnLongClickListener() {
            public boolean onLongClick(View v) {
            return true;
            }
        });
        super.appView.getView().setLongClickable(false);
        Log.i(TAG, "setLongClickable false");
    }
}

It doesn't seem to have any effect. I have also added the following CSS rules:

* {
    -webkit-text-size-adjust: none !important;
    -webkit-touch-callout: none !important;
    -webkit-user-select: none !important;
    user-select: none !important;
  }

This also had no effect.

I have also tried the following Javascript, which runs before any view is rendered (using Backbone/Marionette/Handlebars) (#viewport is the first div element inside body):

  function stopEvent(e) {
    e.preventDefault();
    e.stopPropagation();
    return false;
  }

  window.oncontextmenu = function (e) {
    return stopEvent(e);
  };

  window.onselectstart = function(e) {
    return stopEvent(e);
  };
  window.ondragstart = function(e) {
    return stopEvent(e);
  };

  $('#viewport').on('taphold', function(e) {
    console.log("taphold");
    e.preventDefault();
    e.stopPropagation();

    return false;
  });

Again, no effect.

I'm almost certain it's due to the Cordova Crosswalk WebView, since after removing the plugin, the behaviour disappears: nothing happens on a long-press. Is the Crosswalk WebView perhaps ignoring the setLongClickable / setOnLongClickListener method calls? Perhaps there's another "hidden" WebView that I need to call these methods on?

How can I disable the top bar? I don't mind editing Cordova or Crosswalk Java sources. Thanks.

Edit: Perhaps this is related? https://crosswalk-project.org/jira/browse/XWALK-4786


回答1:


in most scenarios to stop the text copy bar, you have to set the view's properties :

focusable = false
clickable = false

unless you need to click your view for some actions.




回答2:


Looks like this is a bug in Crosswalk, and a PR which fixes it has been submitted:

https://github.com/crosswalk-project/crosswalk/pull/3193



来源:https://stackoverflow.com/questions/31949401/how-to-disable-long-click-which-opens-the-android-top-menu-bar-with-copy-paste-e

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!