我正在使用webview在我的应用程序中呈现一些格式化的东西.对于某些交互(特定于某些dom元素),我使用javascript和WebView.addJavascriptInterface()
.现在,我想要认识一下.不幸的是,onLongTouch
在Android 2.3中,显示了文本选择的句柄.
如何在不设置onTouchListener
和返回true的情况下关闭此文本选择?(然后,与"网站"的互动不再起作用.
Sam*_*uel 116
这对我有用
mWebView.setOnLongClickListener(new OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
return true;
}
});
mWebView.setLongClickable(false);
Run Code Online (Sandbox Code Playgroud)
我没有测试过,如果你不想长按一下引起振动,你可以试试这个:
mWebView.setHapticFeedbackEnabled(false);
Run Code Online (Sandbox Code Playgroud)
小智 31
设置WebKit的CSS属性-webkit-user-select
来none
可以解决这个问题.
用于禁用选择的示例CSS:
* {
-webkit-user-select: none;
}
Run Code Online (Sandbox Code Playgroud)
我想到了!!这就是你如何实现自己的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!
}
Run Code Online (Sandbox Code Playgroud)
这有效.
小智 5
如果您使用,似乎关闭通过长按切割/粘贴
articleView.setWebChromeClient(new WebChromeClient(){...})
Run Code Online (Sandbox Code Playgroud)
请参阅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();
}
});
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
52209 次 |
最近记录: |