问题
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..
回答1:
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;
}
}
回答2:
mWebView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return true;
}
});
回答3:
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("", "");
CSSCoding = CSSCoding.replaceAll("[aA]>", "");
return CSSCoding;
}
}
来源:https://stackoverflow.com/questions/11526676/disable-click-link-or-button-in-a-webview-android