How can I hide the page / webpage unavailable error from the webview?

I want to hide this error and show only a blank page and dialog.

How can I hide this?

+4
source share
2 answers

This is not so obvious. Because WebViewClient will open the standard error page anyway, even if you override the onReceivedError method. Therefore, we need to open the user error page after the processing error event.

So, you have to redefine onReceivedError in WebViewClient , then if you are processing the necessary error code (see ERROR_ constants in WebViewClient), you must open a blank page or another page to hide the standard "Web page is not accessible" page.

Something like that:

@Override public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { if (errorCode == neededErrorCode) { hideErrorPage(view); } } private void hideErrorPage(WebView view) { // Here we configurating our custom error page // It will be blank String customErrorPageHtml = "<html></html>"; view.loadData(customErrorPageHtml, "text/html", null); } 
+10
source

You must override the onReceiveError method.

http://developer.android.com/reference/android/webkit/WebViewClient.html#onReceivedError%28android.webkit.WebView,%20int,%20java.lang.String,%20java.lang.String%29

In this method, simply create your own view for viewing. For example, upload a new URL or some custom html.

+1
source

Source: https://habr.com/ru/post/1439895/


All Articles