webView.setWebViewClient(new WebViewClient(){
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
view.loadUrl("file:///android_asset/error.html");
}
});
loadErrorPage(webView)
功能中调用onReceivedError
功能。以下代码将加载您要显示的错误内容。在这里,我使用loadDataWithBaseURL加载html文件。
public void loadErrorPage(WebView webview){
if(webview!=null){
String htmlData ="<html><body><div align=\"center\" >"This is the description for the load fail : "+description+"\nThe failed url is : "+failingUrl+"\n"</div></body>";
webview.loadUrl("about:blank");
webview.loadDataWithBaseURL(null,htmlData, "text/html", "UTF-8",null);
webview.invalidate();
}
}
您的问题重复了,并且在此链接中也有答案: