Reputation: 117
I have a WebView Activity that sometimes doesn't load up properly due to a disconnected or poor WIFI/DATA connection. 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? For example, instead of a white screen showing up while the WebView is loading, how can I show a loading icon during this moment?
Thanks a lot.
Upvotes: 1
Views: 1220
Reputation: 16062
When a page is not found the page returns a 404 error, what you need to do is handle it.
This can be done by setting a WebViewClient
and overriding onReceivedError
method.
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);
}
});
Upvotes: 3