Marco M Marco M - 1 month ago 25
Android Question

Android WebView Rendering Finished

I'm approching with the android development and webviews.
I want to display the webview just after the rendering has finished, so I got an ImageView visible on the top of the webview. How can i hide the ImageView ONLY after the webview has been rendered?

Answer

You have to enable javascript in your webview and then pass a javascript interface to webview so that you can interact with android code form javascript.

While setting up the webview add these to enable javascript and javascript interface

 webView.getSettings().setJavaScriptEnabled(true);
  webView.addJavascriptInterface(new WebAppInterface(this),
                   "Android");

public class WebAppInterface {
    Context mContext;
    /** Instantiate the interface and set the context */
    WebAppInterface(Context c) {
        mContext = c;
    }

    /** Hide image view */
    @JavascriptInterface
    public void hideImageView() {
        imageView.setVisibilty(View.GONE);
     }  
    }

In javascript call

document.addEventListener('DOMContentLoaded', function() {
   setTimeout(function () 
 { Android.hideImageView(); }, 3000);
}, false);

Note: you need to have this javascript code in your content which you are loading in webview