WebView Show progress bar when loading

Source: Internet
Author: User

Learning from MU-class network, it feels very fun.

Also set a button to jump, are placed inside the inner class.

 PackageCom.example.deemo;Importandroid.app.Activity;ImportAndroid.app.ProgressDialog;Importandroid.content.Intent;ImportAndroid.net.Uri;ImportAndroid.os.Bundle;ImportAndroid.view.View;ImportAndroid.view.View.OnClickListener;Importandroid.webkit.WebChromeClient;ImportAndroid.webkit.WebView;Importandroid.webkit.WebViewClient;ImportAndroid.widget.Button; Public classMainactivityextendsactivity{PrivateString url= "http://www.bilibili.com";//Address    PrivateWebView WebView; PrivateButton bt1; PrivateProgressDialog Dialog; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);        Setcontentview (R.layout.activity_main); BT1=(Button) Findviewbyid (r.id.button1);//uri uri = uri.parse (URL);//Link Address//Intent Intent = new Intent (Intent.action_view,uri);//the above document and the following objectives//startactivity (intent);//to jumpBt1.setonclicklistener (NewOnclicklistener () {@Override Public voidOnClick (View arg0) {init (); }            //Construction Method            Private voidinit () {WebView=(WebView) Findviewbyid (R.id.webview); //Local Resource Webview.loadurl (file:///android_asset/file name)Webview.loadurl (URL);//Open External//overwrite the system browser to open so that the target is open in WebViewWebview.setwebviewclient (Newwebviewclient () { Public Booleanshouldoverrideurlloading (WebView view, String URL) {view.loadurl (URL); return true;//ture to open in WebView                    }                }); //Gets the site loading progressWebview.setwebchromeclient (Newwebchromeclient () {@Override Public voidOnprogresschanged (WebView view,intnewprogress) {                            //newprogress 1~100 Integer                        if(newprogress==100) {//Load CompleteClosedialog (); }Else{//is loadingOpenDialog (newprogress);//Passing Parameters                        }                    }                    Private voidOpenDialog (intnewprogress) {                        if(dialog==NULL) {Dialog=NewProgressDialog (mainactivity. This);//New Progress barDialog.settitle ("Loading in");//display textDialog.setprogressstyle (progressdialog.style_horizontal);//Horizontal progress barDialog.setprogress (newprogress);//Get ProgressDialog.show ();//Show Progress}Else{dialog.setprogress (newprogress); }                            }                    Private voidClosedialog () {if(dialog!=NULL&&dialog.isshowing ())                            {Dialog.dismiss (); Dialog=NULL;            }                    }                });    }        }); }}//this lump of anti-parenthesis ... 

WebView Show progress bar when loading

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.