Home > Tricks & Tips > Load WebView with ProgressDialog

Load WebView with ProgressDialog

It’s very useful to determine the status while loading a web page. Here a sample to show ProgressDialog to track when WebVIew done with loading URL.

public class MainActivity extends Activity {

	WebView mWeb;
	ProgressDialog mProgress;

    public void onCreate(Bundle savedInstanceState) {
        // no need to use title bar
        // set webview as main content only
        mWeb = new WebView(this);
        // set Javascript
        WebSettings settings = mWeb.getSettings();
        // the init state of progress dialog
        mProgress = ProgressDialog.show(this, "Loading", "Please wait for a moment...");

        // add a WebViewClient for WebView, which actually handles loading data from web
        mWeb.setWebViewClient(new WebViewClient() {
        	// load url
        	public boolean shouldOverrideUrlLoading(WebView view, String url) {
        		return true;

        	// when finish loading page
        	public void onPageFinished(WebView view, String url) {
        		if(mProgress.isShowing()) {
        // set url for webview to load

Hope it helps!

Pete Houston

  1. dbhilang
    March 30, 2017 at 9:16 pm

    This is what im looking for.
    florist jakarta

  2. dbhilang
    March 30, 2017 at 9:14 pm

    Worked like charm…thanks
    toko bunga bandung

  3. sd77
    December 7, 2016 at 2:48 am

    Worked fine! Thanks!

  4. fear
    August 27, 2013 at 9:22 am

    change color ProgressDialog?

  5. August 3, 2013 at 9:21 pm

    Thanks a lot! it works well! 🙂

  6. xristina
    October 18, 2012 at 3:56 pm

    Thanks!That was a really good way to load a web view!!!!

  7. Justin
    May 27, 2012 at 3:52 pm

    This is great, but what about when a user clicks on a link inside webview. How do you show a ProgressDialog every time someone clicks on a link inside the web view? This only shows on the first load. I’m pulling my hair out trying to figure this out!

    • April 25, 2013 at 10:10 pm

      have you found the solution yet ??

      • January 8, 2014 at 12:36 am

        I have found a solution.

        Add “mProgress.show();” into the shouldOverrideUrlLoading() function above view.loadUrl(url);

  8. Ferran
    February 6, 2012 at 3:42 pm

    Thanks mate!

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: