Adam Varhegyi
Adam Varhegyi

Reputation: 9914

How to setVisibility(View.VISIBLE) to a webView AFTER its loaded its contents?

In my app there is an advertising web view, that is calling an url when the activity starts. Everything is nice except one minor thing, it is more like a visibility issue... So the thing is when i start the activity i literally see the page loading.. About in 0,3 seconds the texts appear then the pictures, and all the content somehow floating in from left to right. It not so nice, i would like to set the visibility of my webView to VIEW.GONE until it is done with the loading, and after that i could set it VISIBLE...

Is there a good, and working way for achieve this? It is important that it is must work on Android 2.3 to 4.0 in each and every OS version.

I already tried onPageFinished and PictureListener related to this stack question here, but no hope, onPageFinished only works properly on 4.0 and PictureListener is for pictures which is not the best way to do this in case of different advertisings with different number of pictures. (and what if there is no picture at all...)

Please if you know a way let know with me. Thanks all.

Upvotes: 3

Views: 3700

Answers (2)

Suraj
Suraj

Reputation: 243

Use webview visibility during onPageFinished method view not display util all page loading.

webView1.setWebViewClient(new WebViewClient(){

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

                                                    webView1.setVisibility(View.VISIBLE);

                                                }

Upvotes: 1

sunil
sunil

Reputation: 6614

have you tried WebChromeClient ?

webView.setWebChromeClient(new WebChromeClient() {

    public void onProgressChanged(WebView view, int progress) {
        if (progress == 100) {
            // dismisses the PD
            dismissLoadingDialog();
        }
    }
});
    webView.loadUrl("your-Url");
// show message dialog here
createLoadingDialog();

i have used this on 2.3 to 4.0 OSes without any issue

Upvotes: 2

Related Questions