[英]Replace a “Web page not available” Error in WebView with something less ugly? (Android)
I have a WebView Activity that sometimes doesn't load up properly due to a disconnected or poor WIFI/DATA connection. 我有一个WebView活动,由于断开连接或WIFI / DATA连接不良,有时无法正常加载。 I imagine this is more than likely to happen in the real world once my app is deployed.
我想,一旦我的应用程序部署,这很可能发生在现实世界中。 My question is how can I replace this ugly error with something more pretty?
我的问题是如何用更漂亮的东西替换这个丑陋的错误?
Also, do you have any other tips for getting my WebView Activity to NOT resemble a browser? 另外,您是否有任何其他提示让我的WebView Activity不像浏览器? For example, instead of a white screen showing up while the WebView is loading, how can I show a loading icon during this moment?
例如,在加载WebView时,不是显示白屏,而是在这一刻如何显示加载图标?
Thanks a lot. 非常感谢。
When a page is not found the page returns a 404 error, what you need to do is handle it. 当找不到页面时,页面返回404错误,您需要做的就是处理它。
This can be done by setting a WebViewClient
and overriding onReceivedError
method. 这可以通过设置
WebViewClient
并覆盖onReceivedError
方法来完成。
You can Try something like this : 你可以尝试这样的事情:
WebView wv = (WebView) findViewById(R.id.webView);
wv.setWebViewClient(new WebViewClient() {
@Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
//handle the 404
super.onReceivedError(view, errorCode, description, failingUrl);
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.