我有一个webview加载网址“http://www.google.com”..当我们点击该网页视图中的链接或按钮时,我想要禁用活动..我设置clickable =“false”但不能正常工作.. < / p>
答案 0 :(得分:7)
创建自定义WebViewClient
并覆盖shouldOverrideUrlLoading
&amp; shouldOverrideKeyEvent
。例如:
public class MyWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideKeyEvent (WebView view, KeyEvent event) {
// Do something with the event here
return true;
}
@Override
public boolean shouldOverrideUrlLoading (WebView view, String url) {
if (Uri.parse(url).getHost().equals("www.google.com")) {
// This is my web site, so do not override; let my WebView load the page
return false;
}
// reject anything other
return true;
}
}
答案 1 :(得分:5)
mWebView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return true;
}
});
答案 2 :(得分:2)
不知道在webview中禁用HTML Native按钮,但您可以禁用链接
public class formatHTML {
public static String changeHTMLFormat(String htmlObject){
String result = "", CSSCoding = "";
CSSCoding = htmlObject;
CSSCoding = CSSCoding.replaceAll("<[aA].*?>", "<u>");
CSSCoding = CSSCoding.replaceAll("</[aA]>", "</u>");
return CSSCoding;
}
}