英文:
How can I change the previous web page to my own if it did not load in WEB VIEW?
问题
以下是您要翻译的内容:
问题在于当加载新页面时,WEBVIEW会显示先前的页面。如果页面根本没有加载或加载出现错误,则会显示“网页不可用”的消息,我不希望看到这个消息,而是想要隐藏它或替换为自己的消息。如何实现这一点?
<https://cloud.mail.ru/public/321U/4DU3gj9dy> 这是我的Android Studio项目。
存档密码:myapps123
要查找并查看错误,请重新构建项目,并按照以下步骤操作:
将应用安装到您的手机上/
- 启动应用程序。
- 在页面上打开任何链接。
- 关闭互联网,但不要最小化应用程序!
- 打开任何链接。
- 点击两次重新加载。
- 打开互联网,但不要最小化应用程序!(在您的设备上按住主页按钮)
- 使用防火墙阻止应用程序访问互联网。
- 在应用程序菜单栏中单击主页按钮。
- 点击屏幕。
- 点击重新加载,查看错误 - 我想要隐藏这个错误,或者在我的屏幕或页面上替换它。
英文:
P.S my English very bad and I have mistakes in text))) please sorry!
The problem is that when a new page is loaded, WEBVIEW shows the previous one, and if it is not loaded at all or loaded with errors, then it shows the message The web page is not available, which I would not want to see at all, but hide or replace it with my own, how is this possible to implement?
<https://cloud.mail.ru/public/321U/4DU3gj9dy> this is my Android Studio project.
archive password : myapps123
TO FIND and see the error rebuild the project and follow the steps below:
Install the app to your mobile phone/
- Start the application.
- Open any link on the page.
- Turn off the Internet, but do not minimize the application!
- Open any link.
- Click Reload twice
- Turn on the Internet, but do not minimize the application!(hold the home button in tour device
- Block the application accessing to the Internet with a firewall.
- Click on the house button in application menu bar.
9.click on the screen. - Click Reload and see an error - I want to hide this error or replace it on my screen or page.
答案1
得分: 0
你可以在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></html>";
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) {
super.onReceivedError(view, errorCode, description, failingUrl);
// 在这里调用loadErrorPage函数
}
});
英文:
You can call loadErrorPage(view) function in the onReceivedError function.
The following code will load the error content you need to show.Here i am load the html file with loadDataWithBaseURL.
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();
}
}
You can write onReceivedError like that :
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
}
});
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论