Android:在web视图中禁用文本select

我正在使用webview在我的应用程序中呈现一些格式化的东西。 对于一些交互(特定于某些DOM元素),我使用JavaScript和WebView.addJavascriptInterface() 。 现在,我想要认识到一个长期的联系。 不幸的是,在onLongTouch ,在Android 2.3中显示文本select的句柄。

如何在设置onTouchListener 情况下closures此文本select并返回true? (然后,与“网站”的交互不再起作用。

最好的问候,并提前感谢,一月奥利弗Oelerich

这对我工作

 mWebView.setOnLongClickListener(new OnLongClickListener() { @Override public boolean onLongClick(View v) { return true; } }); mWebView.setLongClickable(false); 

我还没有testing,如果你不想长时间点击引起的振荡,你可以试试这个。

 mWebView.setHapticFeedbackEnabled(false); 

将webkit css属性-webkit-user-selectnone将解决问题。

示例CSS禁用select:

 * { -webkit-user-select: none; } 

我想到了!! 这就是你如何实现你自己的longtouchlistener。 在longTouch函数中,您可以调用您的JavaScript界面​​。

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

这工作。

看来,如果你使用了长按剪切/粘贴function,

  articleView.setWebChromeClient(new WebChromeClient(){...}) 

https://bugzilla.wikimedia.org/show_bug.cgi?id=31484

所以,如果您使用setChromeClient,并且想要长时间点击以开始复制/粘贴,请执行以下操作:

  webView.setWebChromeClient(new WebChromeClient(){ [.... other overrides....] // @Override // https://bugzilla.wikimedia.org/show_bug.cgi?id=31484 // If you DO NOT want to start selection by long click, // the remove this function // (All this is undocumented stuff...) public void onSelectionStart(WebView view) { // By default we cancel the selection again, thus disabling // text selection unless the chrome client supports it. // view.notifySelectDialogDismissed(); } }); 

看来,唯一的select是设置onTouchListener并编写自己的代码来检测长按。 如果是长时间点击,则返回true否则返回false