You can do this by implementing a WebViewClient
to your WebView
and using the onPageFinished () determines that the page has been fully loaded, at which point you delete the dialog using the method dismiss()
of ProgressBar
.
final ProgressDialog progressDialog = new ProgressDialog(this);
progressDialog.setIcon(R.mipmap.ic_launcher);
progressDialog.setMessage("Cargando...");
progressDialog.show();
//Obtiene referencia en Layout de WebView.
webView = (WebView) findViewById(R.id.myWebView);
//Carga página.
webView.loadUrl("http://es.stackoverflow.com");
//Define WebViewClient() para poder leer eventos que ocurren durante el cargado de contenido en el WebView.
webView.setWebViewClient(new WebViewClient(){
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
//elimina ProgressBar.
progressDialog.dismiss();
}
});
When the WebView
is in the process of loading the content, the ProgressBar
will be shown, the term disappears.
You can even change the style to look like a progress bar:
progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
As another option, you can even implement a Asynctask
to show the loading progress.
How to display a ProgressBar while getting a response from the server?