In Android apps, sometimes it's better to load a Web page with a progress bar, and Android provides good support.
Which webview a series of uses, such as
Webview.getsettings (). Setjavascriptenabled (True);
Settings can be used with JavaScript webview.setscrollbarstyle (Webview.scrollbars_outside_overlay);
Set scroll bar style webview.sethorizontalscrollbarenabled (false); Webview.getsettings (). Setsupportzoom (True); Webview.getsettings (). Setbuiltinzoomcontrols (True);
The settings can support scaling Webview.setinitialscale (25);
is 25%, the minimum zoom level, where you can set the scale based on your needs. Webview.sethorizontalscrollbaroverlay (TRUE); Here is an example of the program, the first post:
Main program:
public class Webpageloader extends Activity {
Final activity activity = this;
@Override
public void OnCreate (Bundle savedinstancestate)
{
Super.oncreate (savedinstancestate);
This.getwindow (). Requestfeature (window.feature_progress);
Setcontentview (R.layout.main);
WebView WebView = (WebView) Findviewbyid (R.id.webview);
Webview.getsettings (). Setjavascriptenabled (True);
Webview.getsettings (). Setsupportzoom (True);
Click the link in the current browser response, not the new Android system browser should link in the ring
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");
}
}
The use of the progress bar is to write the Onprogresschanged event in the inner class after the new setwebchromeclient.
In the design of webview, not everything should be WebView class dry, some chores are assigned to other people, so webview concentrate on doing their own analysis, rendering work on the line. Webviewclient is to help WebView handle various notifications, request events, specifically including:
Webchromeclient is an auxiliary webview processing JavaScript dialog box, website icon, website title, loading progress etc.
Determine if the loaded page URL address is correct: if (urlutil.isnetworkurl (URL) ==true)
Use WebView, webchromeclient and webviewclient to load Web pages in Android