Android WebView parameter settings details !, Androidwebview

Source: Internet
Author: User

Android WebView parameter settings details !, Androidwebview

WebView wv = new WebView (content );

WebSettings ws = wv. getSettings ();

The configuration parameters are as follows:

SetPluginsEnabled (true); // supports plug-ins

SetUserWideViewPort (false); // adjust the image size to the appropriate webview size.
Setsuppzoom zoom (true); // supports zoom
SetLayoutAlgorithm (LayoutAlgrithm. SINGLE_COLUMN); // supports LayoutAlgrithm. SINGLE_COLUMN.
SupportMultipleWindows (); // multiple windows
SetCacheMode (WebSettings. LOAD_CACHE_ELSE_NETWORK); // disable the cache in webview.
SetAllowFileAccess (true); // you can set the file to be accessed.
SetNeedInitialFocus (true); // set a node for webview when webview calls requestFocus
SetjavaScriptCanOpenWindowsAutomatically (true); // supports opening a new window through JS
SetLoadsImagesAutomatically (true); // supports automatic image loading.
SetBuiltInZoomControls (true );
// Supports Scaling
WebView. setInitialScale (35 );
// Set the scaling ratio
WebView. setScrollBarStyle (View. SCROLLBARS_OUTSIDE_OVERLAY );
// Set the scroll bar to hide
WebView. getSettings (). setGeolocationEnabled (true );
// Enable location
WebView. getSettings (). setRenderPriority (RenderPriority. HIGH );
// Set the rendering priority
String dir = "/sdcard/temp"; // you can specify the path of the target database.
WebView. getSettings (). setGeolocationDatabasePath (dir );
Here we use the settings of webview and webview, and set the course according to the actual situation.
Full solution of WebViewClient Method
DoUpdateVisitedHistory (WebView view, String url, boolean isReload)
Update history
OnFormResubmission (WebView view, Message dontResend, Message resend)
The application re-Requests page data
OnLoadResource (WebView view, String url)
It is called when page resources are loaded, and each resource (slice) is called once.
OnPageStarted (WebView view, String url, Bitmap favicon)
This event is called to load the page. Generally, we can set a loading page to tell the user program to wait for the Network to respond.
OnPageFinished (WebView view, String url)
Call when page loading ends. In the same way, we know that loading a page is complete, so we can close loading entries and switch program actions.
OnReceivedError (WebView view, int errorCode, String description, String failingUrl)
OnReceivedHttpAuthRequest (WebView view, HttpAuthHandler handler, String host, Stirng realm)
Obtain the returned information authorization request onScaleChanged (WebView view, float oldScale, float newScale) when the WebView changes, the onUnhandledKeyEvent (WebView view, KeyEvent event) key event is called when it is not loaded.
ShouldOverrideUrlLoading
It is not called every time before onPageStarted, that is, a new URL does not
ShouldOverrideUrlLoading is called only when webview. loadURL is called.
// Set to open a new webpage 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 );}
// Process alertpublic boolean onJsAlert (WebView view, String url, String message, final JsResult result) in javascript {// construct a Builder to display the dialog box in the webpage
Builder builder = new Builder (mainaciti.pdf. this );
Builder. setTitle ("prompt ");
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 webpage loading progress bar
Public void onProgressChanged (WebView view, int newProgress) {MainAcitivity. this. getWindow (). setFeatureInt (Window. FEATURE_PROGRESS, newProgress * 100 );
Super. onProgressChanged (view, newProgress );}
// Set the application title
Titlepublic void onReceivedTitle (WebView, String title) {MainAcitivity. this. setTitle (title );
Super. onReceivedTitle (view, title );}});
// Determine whether the network is connected
ConnectivityManager cm;
Cm = (ConnectivityManager) getSystemService (Context. CONNECTIVITY_SERVICE );
Boolean isWifiConnected = cm. getNetworkInfo (ConnectivityManager. TYPE_WIFI). getState () = NetworkInfo. State. CONNECTED;
If (! IsWifiConnected) {boolean isuplsconnected = cm. getNetworkInfo (ConnectivityManager. TYPE_MOBILE). getState () = NetworkInfo. State. CONNECTED;
If (! Isuplsconnected) {new AlertDialog. builder (this ). setTitle ("prompt "). setMessage ("offline status, enable offline mode "). setPositiveButton ("OK", null ). show () ;}else {result = CallWCF ();}}

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.