in Android applications, sometimes a webpage needs to be loaded. If a progress bar can be configured, android
provides excellent support, the following is an example of Program . Post it first:
<? XML version = "1.0" encoding = "UTF-8"?> <Webview xmlns: Android = "http://schemas.android.com/apk/res/android" Android: Id = "@ + ID/webview" Android: layout_width = "fill_parent" Android: layout_height = "fill_parent"/>
Main Program:
Public class webpageloader extends activity {final activity = This; @ override public void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); this. getwindow (). requestfeature (window. feature_progress); setcontentview (R. layout. main); webview = (webview) findviewbyid (R. id. webview); webview. getsettings (). setjavascriptenabled (true); webview. getsettings (). setsuppzoom zoom (true); webview. setwebchromeclient (New webchromeclient () {public void onprogresschanged (webview view, int progress) {activity. settitle ("loading... "); activity. setprogress (Progress * 100); If (Progress = 100) activity. settitle (R. string. app_name) ;}}); webview. setwebviewclient (New webviewclient () {public void onreceivederror (webview view, int errorcode, string description, string failingurl) {// handle the error} public Boolean shouldoverrideurlloading (webview view, string URL) {view. loadurl (URL); Return true ;}}); webview. loadurl ("http://www.sohu.com ");}}
It should be noted that a series of webview usage, such as webview. getsettings (). setjavascriptenabled (true); javscript can be used for setting;
webview. getsettings (). setjavascriptenabled (true); webview. setscrollbarstyle (webview. scrollbars_outside_overlay); webview. sethorizontalscrollbarenabled (false); webview. getsettings (). setsuppzoom zoom (true); webview. getsettings (). setbuiltinzoomcontrols (true); webview. setinitialscale (70); webview. sethorizontalscrollbaroverlay (true);
For more information, see the API
The progress bar can be written in the internal class after a new setwebchromeclient is generated.
Onprogresschanged event
In the design of webview, The webview class is not required to do anything. Some chores are assigned to others, so that webview can focus on parsing and rendering. Webviewclient helps webview process various notifications and request events, including:
Onloadresource
Onpagestart
Onpagefinish
Onreceiveerror
Onreceivedhttpauthrequest
Webchromeclient is a dialog box that assists webview in processing Javascript, website icons, website titles, loading progress, etc.
Onclosewindow (disable webview)
Oncreatewindow ()
Onjsalert)
Onjsprompt
Onjsconfirm
Onprogresschanged
Onreceivedicon
Onreceivedtitle