3

我有一个 webview 加载 URL“http://www.google.com”..当我们单击该 webview 中的链接或按钮时,我想禁用事件..我设置 clickable="false" 但不起作用..

4

3 回答 3

8

创建一个自定义WebViewClient并覆盖 shouldOverrideUrlLoading& 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;
    }
}
于 2012-07-17T16:22:33.667 回答
6
mWebView.setOnTouchListener(new View.OnTouchListener() {
    @Override
    public boolean onTouch(View v, MotionEvent event) {
       return true;
    }  
});
于 2015-06-27T09:00:45.683 回答
3

不知道在 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;
    }     
}
于 2012-07-17T16:23:11.540 回答