Android WebView parameter settings details!

Source: Internet
Author: User

WebView WV = new WebView (content);

WebSettings ws = Wv.getsettings ();

Set the parameter details as follows:

Setpluginsenabled (TRUE);//Support Plugin

Setuserwideviewport (FALSE);//adjust the picture to fit the WebView size
Setsupportzoom (TRUE);//Support Scaling
Setlayoutalgorithm (Layoutalgrithm.single_column);//support content from new layout
supportmultiplewindows ();//multi-window
Setcachemode (websettings.load_cache_else_network);//close webview in cache
setallowfileaccess (TRUE);//settings can access files
Setneedinitialfocus (TRUE);//Set node for WebView when WebView calls Requestfocus
setjavascriptcanopenwindowsautomatically (TRUE);//support to open a new window via JS
setloadsimagesautomatically (TRUE);//supports automatic loading of pictures
Setbuiltinzoomcontrols (true);
//Support scaling
Webview.setinitialscale (+);
//Set zoom ratio
Webview.setscrollbarstyle (view.scrollbars_outside_overlay);
//Set scroll bar hide
webview.getsettings (). Setgeolocationenabled (true);
//Enable geo-targeting
webview.getsettings (). setrenderpriority (Renderpriority.high);
//Set render priority
String dir = "/sdcard/temp";//Set the location of the database path
webview.getsettings (). Setgeolocationdatabasepath (dir);
here are the relevant settings for using WebView and WebView, which are set according to the actual situation.
the whole solution of the method of Webviewclient
doupdatevisitedhistory (WebView view, String URL, boolean isreload)
Update History
onformresubmission (WebView view, message dontresend, message resend)
application re-requesting page data
Onloadresource (WebView view, String URL)
called when a page resource is loaded, and each resource (a slice) is loaded once
onpagestarted (WebView view, String URL, Bitmap favicon)
This event is to start loading the page call, usually we can set a loading in this page, tell the user program is waiting for the network corresponding.
onpagefinished (WebView view, String URL)
called at the end of the page load, the same thing, we know a page loading is complete, so we can close the loading bar, switch program action.
Onreceivederror (WebView view, int errorCode, string description, String failingurl)
report error message Onreceivedhttpauthrequest (WebView view, Httpauthhandler handler, String host,stirng Realm)
Gets the return information authorization request onscalechanged (WebView view, float Oldscale, float newscale) WebView When a change is called onunhandledkeyevent (WebView View, KeyEvent Event) key event is not loaded when called
shouldoverrideurlloading
It's not always called before onpagestarted, which means that a new URL doesn't go through every time .
shouldoverrideurlloading, it is only called when the Webview.loadurl is called.
//Set to open a new page in the same WebView
webview.setwebviewclient (New Webviewclient () {public Boolean shouldoverrideurlloading (WebView view, String URL) { View.loadurl (URL); return true; } });
//Set Webchromeclientwebview.setwebchromeclient (new Webchromeclient () {//configure permissions
Public void Ongeolocationpermissionsshowprompt (String origin,geolocationpermissions.callback Callback) { Callback.invoke (origin, True, false);
Super.ongeolocationpermissionsshowprompt (origin, callback);}
//Processing Alertpublic Boolean Onjsalert (WebView view, string URL, String message, final Jsresult result) in JavaScript {//Build a Builder to display a dialog box in a Web page
Builder builder = new Builder (mainacitivity.this);
builder.settitle ("hint");
builder.setmessage (message);
Builder.setpositivebutton (Android. R.string.ok,new Alertdialog.onclicklistener () {public void OnClick (Dialoginterface dialog, int which) {result.confirm ( );}});
builder.setcancelable (false);
builder.create ();
builder.show ();
return true;
@Override//Set the progress bar for page loading
Public void onprogresschanged (WebView view, int newprogress) {MainAcitivity.this.getWindow (). Setfeatureint ( Window.feature_progress, newprogress *);
super.onprogresschanged (view, newprogress);}
//Set the title of the application
titlepublic void Onreceivedtitle (WebView view, String title) {MainAcitivity.this.setTitle (title);
super.onreceivedtitle (view, title);});
//Determine if networking
Connectivitymanager cm;
cm = (Connectivitymanager) getsystemservice (context.connectivity_service);
boolean iswificonnected=cm.getnetworkinfo (Connectivitymanager.type_wifi). GetState () = = NetworkInfo.State.CONNECTED;
if (!iswificonnected) {Boolean isgprsconnected=cm.getnetworkinfo (connectivitymanager.type_mobile). GetState () = = NetworkInfo.State.CONNECTED;
if (!isgprsconnected) {new Alertdialog.builder (this). Settitle ("hint"). Setmessage ("Offline status, enable Offline mode"). Setpositivebutton ("OK", null). Show (); }else{result = CALLWCF ();}}

Android WebView parameter settings details!

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.