Jack Dsilva Jack Dsilva - 5 months ago 46
Android Question

How to show a progress bar for a layout until the WebView is loaded

I am loading a WebView to the LinearLayout and want to display a ProgressBar inside this layout until the WebView is fully loaded.I wnet through the below links and they seems to be really great but I do not want to use ProgressDialog, instead I would like to use progressbar inside the layout.

http://xjaphx.wordpress.com/2011/07/31/load-webview-with-progressdialog/

how to show progress bar on webview?

How would I do that?

Say for example,

if(pos==0)
{
mLayout.setVisibility(View.VISIBLE);
mWeb.loadUrl("http://android.stackexchange.com/");
}


Inside
mLayout
I would like to display a progressbar until the page gets displayed.

Answer

You can simply use the webView setPictureListener() like this:

// here you can start a loading wheel

   webView.setPictureListener(new WebView.PictureListener() {
      public void onNewPicture(WebView webView, Picture picture) {
           // close your loading wheel here
            }
        });

   //load your url
   webView.loadUrl(yourUrl);