如何禁用长时间打开Android顶部菜单栏与复制/粘贴/等。 Cordova Crosswalk应用程序中的按钮? [英] How to disable long-click which opens the Android top menu bar with copy/paste/etc. buttons in Cordova Crosswalk apps?

查看:871
本文介绍了如何禁用长时间打开Android顶部菜单栏与复制/粘贴/等。 Cordova Crosswalk应用程序中的按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如标题所示,我有一个Cordova应用程序,其中安装了Cordova Crosswalk插件,并在Android和iOS上运行。

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

特别是在Android上,至少在Android 5.1.1和4.4.4版本上(可能是由于Crosswalk而导致的),每当我长按一个输入字段,我的WebView高度缩小,并显示一个奇异的顶部条与剪切/复制/粘贴/剪贴板按钮和一个后退按钮,关闭顶部栏:

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:

如何防止这种长时间点击?我试图在应用程序的MainActivity.java中添加一个onLongClickListener并在WebView上调用setLongClickable(false),如下所示:

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");
    }
}

它似乎没有任何效果。我还添加了以下CSS规则:

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;
  }

这也没有效果。

我也尝试过下面的Javascript,它在渲染任何视图之前运行(使用Backbone / Marionette / Handlebars)(#viewport是body中的第一个div元素):

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;
  });

同样,没有效果。

几乎肯定是由于Cordova Crosswalk WebView,因为删除插件后,行为消失:长按没有发生。是Crosswalk WebView可能忽略setLongClickable / setOnLongClickListener方法调用吗?也许还有另一个隐藏的WebView,我需要调用这些方法?

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?

如何禁用顶部栏?我不介意编辑Cordova或Crosswalk Java源代码。感谢。

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

编辑:也许这是相关的? https://crosswalk-project.org/jira/browse/XWALK-4786

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

推荐答案

看起来这是Crosswalk中的错误,修复它的PR已提交:

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

这篇关于如何禁用长时间打开Android顶部菜单栏与复制/粘贴/等。 Cordova Crosswalk应用程序中的按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆