Not able to clear webPage not available message in web view.
book.clearView() in onReceivedError method is not clearing the WebView, still the webPage not available message is getting displayed when failed to load WebView,any help would be appreciated.
final WebView book = (WebView)findViewById(R.id.book);
//book.setBackgroundColor(Color.parseColor("#123456"));
book.setBackgroundColor(0);
book.setBackgroundResource(R.drawable.pnr)
WebSettings settings = book.getSettings();
settings.setJavaScriptEnabled(true);
book.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
final AlertDialog alertDialog = new AlertDialog.Builder(this).create();
final ProgressDialog dialog =ProgressDialog.show(AboutApp.this,null, "Loading...");
book.setWebViewClient(new WebViewClient(){
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
// TODO Auto-generated method stub
//dialog = ProgressDialog.show(AboutApp.this,null, "Loading...");
super.onPageStarted(view, url, favicon);
}
@Override
public void onPageFinished(WebView view, String url) {
// TODO Auto-generated method stub
if(dialog.isShowing()){
dialog.dismiss();
}
super.onPageFinished(view, url);
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
// TODO Auto-generated method stub
//Log.i(TAG, "Processing webview url click...");
view.loadUrl(url);
return true;
}
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
// Log.e(TAG, "Error: " + description);
//Toast.makeText(activity, "Oh no! " + description, Toast.LENGTH_SHORT).show();
book.clearView();
alertDialog.setTitle("Error");
alertDialog.setMessage("Sorry, This particular service is unavailable at this time.Please try again later");
alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
finish();
return;
}
});
alertDialog.show();
}
});
book.loadUrl("www.google.com");
We need to design our own html file , place that file under assests folder and using loadUrl() method load the html file. eg : book.loadUrl(“file:///android_asset/error.html”);