3

I am trying to display image before the page is fully loaded in a webView but the webview is displaying blank for few moment and then displaying the desided page the amount of time its showing blank screen i want to display some image.I am using webview inside viewpager.

i have tried onPageStarted,onPageFinished method but without any success.

Here is the code:

       web.setWebViewClient(new WebViewClient() {
                    // load url
                    public boolean shouldOverrideUrlLoading(WebView view, String url) {
                        view.loadUrl(url);
                        return true;
                    }

                    // when finish loading page
                    public void onPageFinished(WebView view, String url) {
                        web.setVisibility(View.VISIBLE);
                        image.setVisibility(View.GONE);
                    }
                });

                    <ImageView
                        android:id="@+id/imageviewloading"
                        android:layout_width="wrap_content"
                        android:layout_height="0dip"
                        android:layout_gravity="center"
                        android:layout_weight="1"
                        android:contentDescription="@string/app_name"
                        android:src="@drawable/photo_downloading" />

                    <WebView
                        android:id="@+id/website"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:visibility="gone" />
                </LinearLayout>
Akram
  • 7,548
  • 8
  • 45
  • 72
  • Have you tried AsyncTask for doing the functionality? As the behavior required by you can be easily achieved through doInBackground and onProgressUpdate of AsyncTask. – Roll no1 Mar 01 '12 at 12:12
  • yeah i used that too.but i dont want to use here. – Akram Mar 01 '12 at 12:24

2 Answers2

2

Its

   webview.setWebChromeClient(new WebChromeClient() { 
         public void onProgressChanged(WebView view, int progress) {   
                       // Activities and WebViews measure progress with different scales.    
         // The progress meter will automatically disappear when we reach 100% 
            activity.setProgress(progress * 1000);  
             }
              });

which did the trick for me

Akram
  • 7,548
  • 8
  • 45
  • 72
2

You can jump on the page load started and page load finished events in WebView like this:

myWebView.setWebViewClient(new WebViewClient() {
    @Override
    public void onPageStarted(WebView view, String url, Bitmap favicon) {
        super.onPageStarted(view, url, favicon);
        // Show placeholder icon here
        }

    @Override
    public void onPageFinished(WebView view, String url) {
        super.onPageFinished(view, url);
        // Hide placeholder image here
        }
    });
Ollie C
  • 28,313
  • 34
  • 134
  • 217
  • i tried but showing white screen then i came with the idea you can check with my code. – Akram Mar 01 '12 at 12:01
  • I don't know what you mean by it "showing white screen". By setting background colours you can easily see what that white area is. Is it the WebView? Is it the ImageView? If neither, then your layout is not right (I can't tell as you only posted part of it). If it's the WebView, then your page load is either failing, or you're loading a white page. – Ollie C Mar 01 '12 at 12:36
  • you are correct about one thing here yeah the background is white and second thing you mentioned page load is failing this is not the case here.My webpage is being display but its taking sometime and i want to display some image until the page is not fully loaded. check my question again dear. – Akram Mar 01 '12 at 12:44