I want to change page from Webpage not Available
or ERR_NAME_NOT_RESOLVED
to My Page \"No Internet Connection\"?
a
Replace default WebChromeClient with your custom CustomWebviewClient as below
webView!!.setWebViewClient(object : CustomWebviewClient()
then create this custom WebViewClient
inner class CustomWebviewClient : WebViewClient() {
override fun onPageStarted(view: WebView, url: String, favicon: Bitmap) {
super.onPageStarted(view, url, favicon)
}
override fun onPageFinished(view: WebView, url: String) {
super.onPageFinished(view, url)
}
override fun onReceivedError(view: WebView, request: WebResourceRequest, error: WebResourceError) {
super.onReceivedError(view, request, error)
if (noInternetConnection()) {
loadNoInternetErrorView()
} else {
loadErrorMessageView()
}
}
}
whenever your WebView fails to load page it calls onReceivedError
callback there you can show error layout. For error view you can create error layout within your layout with initial visiblity View.GONE and make it visible when error occurrs.
Changes to your XML file
................
//error view
In loadErrorMessageView you can do this
loadErrorMessageView() {
webview.setVisibility(View.GONE);
error_screen.setVisibility(View.VISIBLE);
error_msg.setText("Some error Occurred");
}
Similarly you can do for NoInternet case maybe you can show "No internet message" than "Some error occurred" I hope this clears your doubt