Skip to content Skip to sidebar Skip to footer

How To Show Loading Image Or Progress Bar On Webview

I have a webView in android that loads a particular site, i want to display a loading icon or progress bar on clicking any of the links inside the webView. webViewClient = (Web

Solution 1:

publicclassCustomWebViewClientextendsWebViewClient {
        @OverridepublicvoidonPageStarted(WebView view, String url, Bitmap favicon) {
            showProgressBar();
        }

        @OverridepublicvoidonPageFinished(WebView view, String url) {
            hideProgressBar();
        }
    }


    webViewClient.setWebViewClient(newCustomWebViewClient());

Solution 2:

 webViewClient = (WebView) findViewById(R.id.contentContainer);

    WebSettings webSettings = webViewClient.getSettings();

    webSettings.setJavaScriptEnabled(true);

    webViewClient.setWebViewClient(new WebViewClient(){

     publicvoidonProgressChanged(WebView view, int progress) {
             activity.setTitle("Loading...");
             activity.setProgress(progress * 100);
                if(progress == 100)
                   activity.setTitle("Your Title");
             });

    webViewClient.loadUrl("URL");

Following Link May help you as well : http://www.firstdroid.com/2010/08/04/adding-progress-bar-on-webview-android-tutorials/

Solution 3:

First, you have to figure out when the click happens :

webView.setWebViewClient(newWebViewClient() { 
            publicbooleanshouldOverrideUrlLoading(WebView view, String url){
                webView.loadUrl(url); 
                // Here the String url hold 'Clicked URL' returnfalse; 
            } 
        });

Then, you have to put the Progressbar in a FrameLayout with your WebView.

<FrameLayout 
android:layout_width="match_parent"android:layout_height="match_parent">

<Progressbar
android:layout_width="wrap_content"android:layout_height="wrap_content">

<WebView
android:layout_width="match_parent"android:layout_height="match_parent">

</FrameLayout> 

So, when the click happens, you can show your progressbar inside your Activity.

webView.setWebViewClient(newWebViewClient() { 
            publicbooleanshouldOverrideUrlLoading(WebView view, String url){
            if (url.equals("your_url"){
            progressbar.setVisibility(View.VISIBLE);
            } 
                returnfalse; 
            } 
        });

Post a Comment for "How To Show Loading Image Or Progress Bar On Webview"