Android:在 webview 中禁用文本选择 [英] Android: Disable text selection in a webview

查看:61
本文介绍了Android:在 webview 中禁用文本选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 webview 在我的应用程序中显示一些格式化的内容.对于某些交互(特定于某些 dom 元素),我使用 javascript 和 WebView.addJavascriptInterface().现在,我想识别长按.不幸的是,onLongTouch,在Android 2.3 中显示了文本选择的句柄.

I am using a webview to present some formatted stuff in my app. For some interaction (which are specific to certain dom elements) I use javascript and WebView.addJavascriptInterface(). Now, I want to recognize a long touch. Unfortunately, onLongTouch, in Android 2.3 the handles for text selection are displayed.

如何在不设置onTouchListener 的情况下关闭此文本选择并返回true?(然后,与网站"的交互不再起作用.

How can I turn off this text selection without setting the onTouchListener and return true? (Then, the interaction with the "website" doesn't work anymore.

推荐答案

我想通了!!这就是您可以实现自己的 longtouchlistener 的方式.在 longTouch 函数中,您可以调用您的 javascript 界面.

I figured it out!! This is how you can implement your own longtouchlistener. In the function longTouch you can make a call to your javascript interface.

var touching = null;
$('selector').each(function() {
    this.addEventListener("touchstart", function(e) {
        e.preventDefault();
        touching = window.setTimeout(longTouch, 500, true);
    }, false);
    this.addEventListener("touchend", function(e) {
        e.preventDefault();
        window.clearTimeout(touching);
    }, false);
});

function longTouch(e) {
    // do something!
}

这行得通.

这篇关于Android:在 webview 中禁用文本选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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