WebView with loader in android example

WebView with loader in Android example

WebView with loader android example is used to show to loading bar when the webpage loading in the WebView after the load complete the loader will disappear.

WebView with loader in Android example
WebView with loader in Android Demo
Simple steps to create Webview with loader,
1. Add Internet Permission in your AndroidManifest.xml.
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
2. Create Webview in the XML layout,
<WebView
android:id="@+id/webView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
3. Setup the Webview and Progressbar in your MainActivity,
//Get webview 
webView = (WebView) findViewById(R.id.webView1);
final ProgressDialog progDailog = ProgressDialog.show(ShowWebView.this, "Loading..","Please wait.. ", true);
progDailog.setCancelable(false);
//terms_of_service_webview.getSettings().setJavaScriptEnabled(true);     
webView.getSettings().setUseWideViewPort(true); 
webView.getSettings().setLoadWithOverviewMode(true);

4. Set the onLoadResource and onPageFinished by set the setWebViewClient in the Webview,

webView.setWebViewClient(new WebViewClient(){
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                progDailog.show();
                view.loadUrl(url);

                return true;                
            }
            @Override
            public void onPageFinished(WebView view, final String url) {
                progDailog.dismiss();
            }
        });
5. Finally, load the URL in the Webview,

webView.loadUrl("http://35.200.174.74");
Screenshot
webview with loader example
Download

 

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to Top