如何在Android中禁用对WebView的长按 [英] How to disable long click on WebView in android
本文介绍了如何在Android中禁用对WebView的长按的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想禁用对webView的长时间单击,因此无法选择其中的文本,我使用三种方法来做到这一点,但无济于事:
1)android:longClickable ="false"2)webView.setLongClickable(false);3)webView.setOnLongClickListener(new OnLongClickListener(){@Overridepublic boolean onLongClick(View v){返回true;}});
所以请帮忙.
解决方案
要禁用长按,您需要先启用长按 setLongClickable(true);
,然后再启用 setOnLongClickListener
,什么也不返回:
webview.setLongClickable(true);webview.setOnLongClickListener(new OnLongClickListener(){@Overridepublic boolean onLongClick(View v){返回true;}});
如果只需要禁用文本选择,最好将以下CSS添加到您的网页中,这将禁用文本选择:
body {-webkit-touch-callout:无;-webkit-user-select:无;-khtml-user-select:无;-moz-user-select:无;-ms-user-select:无;用户选择:无;}
在此处中查看Mozilla文档...>
I want to disable the long click on webView so I cant select the text in it, and I use three ways to do that but nothing work:
1) android:longClickable="false"
2) webView.setLongClickable(false);
3) webView.setOnLongClickListener(new OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
return true;
}
});
So any help please.
解决方案
To disable long clicks you need to first enable long click setLongClickable(true);
then the setOnLongClickListener
, and return nothing:
webview.setLongClickable(true);
webview.setOnLongClickListener(new OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
return true;
}
});
If you only need to disable text selection it's better to add the following CSS to your webpage and it will disable text selection:
body {
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
Check the Mozilla documentation here.
这篇关于如何在Android中禁用对WebView的长按的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文