4

I want to display a progress bar while the WebView is loading. I am hiding it on OnPageFinished(), but this is too early. The Webview is still rendering the image.

The WebView documentation states: "When onPageFinished() is called, the rendering picture may not be updated yet. To get the notification for the new Picture, use onNewPicture(WebView, Picture)."

However, OnNewPicture and the PictureListener interface is deprecated and obsolete. Is there another way to know that the rendering is complete?

Kevin Westwood
  • 7,739
  • 8
  • 38
  • 52

4 Answers4

3

Unfortunately, I have found that there is no event or mechanism to truly know when the page is completely loaded and finished rendering.

Kevin Westwood
  • 7,739
  • 8
  • 38
  • 52
2

How about creating a custom WebChromeClient and overriding its onReceivedIcon() or onProgressChanged() methods. The onReceivedIcon() will be triggered once the favIcon is loaded and and using the onProgressChanged(), you can enquire the progress of the webview loading. I hope this helps

Please refer to this code snippet

webView.setWebChromeClient(new CustomWebChromeClient());

You can use onProgressChanged or onReceivedIcon whatever that suits your needs.

public class CustomWebChromeClient extends WebChromeClient {

    @Override
    public void onProgressChanged(WebView view, int newProgress) {
        super.onProgressChanged(view, newProgress);

        if (newProgress==100) {
            progressBar.setVisibility(View.GONE);
            progressBar.setProgress(newProgress);
        }
    }

    @Override
    public void onReceivedIcon(WebView view, Bitmap icon) {
        // icon received here
        super.onReceivedIcon(view, icon);
    }
}
Bijay Koirala
  • 525
  • 5
  • 9
1

I think you can add and execute JavaScript function at the end of body tag of your web page to call your JavaScript interface function to hide the progress bar. But, beware of enabling JavaScript on your WebView.

Wastono
  • 11
  • 1
1

I'm suffering same problem, but there is no way to know the timing. The only way I use is to give enough room for the rendering completion by postDelayed().

In my case 200ms is enough if u don't use heavy contents more than 200K in text.

chidoo
  • 11
  • 1