webview自定义错误页面无法正常工作? [关闭]

问题描述 投票:0回答:1
在没有互联网连接的情况下打开错误页面,它正在打开默认错误,但是当我按回去时,它正在工作并打开我的错误html页面。当我在没有网络连接的情况下打开应用程序时,它会显示带有url的默认错误,并且在我按返回按钮后,它会打开我的html错误页面。

webView.setWebViewClient(new WebViewClient(){ public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { view.loadUrl("file:///android_asset/error.html"); } });

android android-studio webview custom-error-pages
1个回答
0
投票
您可以在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(); } }

您的问题重复了,并且在此链接中也有答案:

Android webview custom error page

© www.soinside.com 2019 - 2024. All rights reserved.