R.Y R.Y - 1 month ago 11
Android Question

How to know if webView started rendering in android

I am loading a pdf in

WebView
.

WebView webView = new WebView(this);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setPluginState(WebSettings.PluginState.ON);
webView.setWebViewClient(new WebViewClient());

String url = "http://drive.google.com/viewerng/viewer?embedded=true&url=http://" + getIntent().getStringExtra("url");

webView.loadUrl(url);
setContentView(webView);


Whenever the activity is started,
WebView
is shown blank. But I want to show a progress dialog till the
WebView
starts rendering pdf file. How can I add a listener to the
WebView
indicating that the files has been started visible to the user.

Jai Jai
Answer

You could create custom class and extend it with WebViewClient. Then override method onPageStarted where you could consider that it started rendering. For e.g :

private class CustomWebClient extends WebViewClient {

@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
      super.onPageStarted(view, url, favicon);

      showProgress();

   }
   @Override
   public void onPageFinished(WebView view, String url) {
       super.onPageFinished(view, url);
       dismissDialog();
   }

}
Comments