Is there a listener for when the WebView displays it’s content?

I successfully used Richard’s answer with a PictureListener for a few years, but I no longer recommend this as the best solution.

This is for two reasons:

  1. webView.setPictureListener and PictureListener are both deprecated.
  2. Using this listener will cause the WebView to allocate a new Picture often. This allocation is expensive and this can have some significant performance impacts or even cause native crashes on JellyBean MR1.

Instead I recommend creating a subclass of WebView and overriding invalidate() like so:

@Override
public void invalidate() {
    super.invalidate();

    if (getContentHeight() > 0) {
        // WebView has displayed some content and is scrollable.
    }
}

If you still want to use the PictureListener method, you will get better performance if you setPictureListener back to null after you are done with it.

Leave a Comment