Android – ProgressDialog display before Loading Webpage in WebView

“How to implement progressBar or progressDialog while Webview loading Webpage?” I googled many times for this question and get best answer which i want to post here so it will be helpful to others also.

Basically User Interaction is main thing in any application and this question is also related to User Interaction.

You can implement it using setWebChromeClient() of WebView:

class MyWebChromeClient extends WebChromeClient {

ProgressDialog pDialog;

public MyWebChromeClient() {
// TODO Auto-generated constructor stub
pDialog
= new ProgressDialog(YourActivity.this); //Use getActivity(); for Fragment
pDialog
.setMessage("Loading...");
pDialog
.setCancelable(false);
pDialog
.setProgress(0);
pDialog
.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);

}

public void onProgressChanged(WebView view, int progress)
{
if(progress < 100 && !pDialog.isShowing()){
pDialog
.show();
}
pDialog
.setProgress(progress);
if(progress == 100) {
pDialog
.dismiss();
}
}
}
and you can set on your WebView like
webView.setWebChromeClient(new MyWebChromeClient());
I have posted this answer on stackoverflow also so you can visit and share it.
Any Question? You can ping me any time.

Page Views (33)

600 Total Views 1 Views Today
Share Love & Support:

About Pratik Butani

Pratik Butani is Enthusiastic Android Application Developer, Speaker at Google Developer Group – Rajkot, All time Learner of new things, Googler, Eager to Help IT Peoples. He also like to TEACH Android to New Learner and Share his knowledge to them. He is currently working as a Senior Android Developer at Soham ERP Solutions Pvt. Ltd. – Ahmedabad. He is working with Android Development since 2013 and now Flutter is on going.

Comment Your Suggestion or Appreciation:

Loading Facebook Comments ...

Leave a Reply

Your email address will not be published. Required fields are marked *