Disable click link or button in a webview Android

前端 未结 3 775
长发绾君心
长发绾君心 2021-01-03 12:54

I have a webview load URL \"http://www.google.com\"..I want disable event when we click link or button in that webview..I set clickable=\"false\" but not work..

相关标签:
3条回答
  • 2021-01-03 13:03
    mWebView.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
           return true;
        }  
    });
    
    0 讨论(0)
  • 2021-01-03 13:10

    Create a custom WebViewClient and override shouldOverrideUrlLoading & shouldOverrideKeyEvent. For example:

    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;
        }
    }
    
    0 讨论(0)
  • 2021-01-03 13:20

    No idea to disable HTML Native button in webview but you can disable link

    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;
        }     
    }
    
    0 讨论(0)
提交回复
热议问题