java - 如果以前的网页没有在 WEB VIEW 中加载,如何将其更改为我自己的网页?
问题描述
PS我的英语很差,我的文字有错误)))请抱歉!问题是,当加载新页面时,WEBVIEW 显示前一个页面,如果根本没有加载或加载错误,则会显示消息网页不可用,我不想看到全部,但隐藏或用我自己的替换它,这怎么可能实现? https://cloud.mail.ru/public/321U/4DU3gj9dy这是我的 Android Studio 项目。存档密码:myapps123
查找并查看错误重建项目并按照以下步骤操作:将应用程序安装到您的手机/
- 启动应用程序。
- 打开页面上的任何链接。
- 关闭互联网,但不要最小化应用程序!
- 打开任何链接。
- 单击重新加载两次
- 打开互联网,但不要最小化应用程序!(按住游览设备中的主页按钮:-)
- 使用防火墙阻止应用程序访问 Internet。
- 单击应用程序菜单栏中的房屋按钮。9.点击屏幕。
- 单击重新加载并查看错误 - 我想隐藏此错误或在我的屏幕或页面上替换它。
解决方案
您可以在 onReceivedError 函数中调用 loadErrorPage(view) 函数。
以下代码将加载您需要显示的错误内容。这里我使用 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();
}
}
你可以这样写 onReceivedError :
WebView wv = (WebView) findViewById(R.id.webView);
wv.setWebViewClient(new WebViewClient() {
@Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
suåper.onReceivedError(view, errorCode, description, failingUrl);
//call loadErrorPage function here
}
});
推荐阅读
- asp.net - HTTPS 安全性受到 ASP.NET Ajax 客户端框架的影响
- amazon-web-services - 将 www 流量重定向到 nginx AWS Elastic Beanstalk 中的非 www
- wordpress - 将外部 URL 添加到 WordPress 的 WooCommerce 类别
- awk - 使用 awk 填充文件
- php - 如何使这个简单的表单正常运行?
- python - 如何更改 Matplotlib 3d 绘图中的边框颜色?
- javascript - 如果我链接我的 CSS,我网站内的谷歌地图不起作用
- bash - 为什么“set VAR=value”在 bash 中不起作用?
- nativescript - 使用 NativeScript 读取设备的接近传感器
- jquery - 使用自定义复选框 CSS 的 jQuery 验证在表单验证后不起作用