Android WebView Use this article to copy directly http://www.cnblogs.com/zgz345/p/3768174.html here. Because the feeling of writing is very comprehensive, directly to use.
1. Instead of invoking the system browser when opening a Web page, it is shown in this webview:
Mwebview.setwebviewclient (new webviewclient () { @Override boolean Shouldoverrideurlloading (WebView view, String URL) { view.loadurl (URL); true;});
2. Invoking JavaScript through Java code
WebSettings websettings = mwebview. getsettings (); Websettings.setjavascriptenabled (true); Mwebview.addjavascriptinterface (new Object () { void clickonandroid () {mhandler.post (newvoid run () {Webview.loadurl ("Javascript:wave ()"
3. When you press the back key, do not exit the program but return to the previous browse page:
Boolean onKeyDown (int keycode, keyevent event) { if (keycode = = keyevent.keycode_back) && TrueSuper. OnKeyDown (KeyCode, event);}
4. When the page is opened, the adaptive screen:
WebSettings websettings = mwebview. getsettings (); Websettings.setusewideviewport (true);//Set this property to scale Websettings.setloadwithoverviewmode (true) at any scale;
5. The page supports zooming:
WebSettings websettings = mwebview. getsettings (); Websettings.setjavascriptenabled (true); Websettings.setbuiltinzoomcontrols (true); Websettings.setsupportzoom (true);
6. If the user is required to manually enter a user name, password, or other webview, the WebView must set the support acquisition gesture focus.
Webview.requestfocusfromtouch ();
7.WebView loading interface mainly calls three methods: Loadurl, LoadData, Loaddatawithbaseurl.
1, Loadurl directly load the webpage, the picture and displays. (Local or Web pages, pictures, gifs) 2, LoadData display text and picture content (simulator 1.5, 1.6) 3, Loaddatawith Base display text and picture content (multiple emulator versions supported)
Introduction to the common methods of 8.WebSettings
Setjavascriptenabled (true);//Support JS
Setpluginsenabled (true);//Support Plugins
Setusewideviewport (FALSE);//Adjust the picture to fit the size of the WebView
Setsupportzoom (true);//Support Scaling
Setlayoutalgorithm (Layoutalgorithm.single_column);//Support for content re-layout
Supportmultiplewindows ();//Multi-window
Setcachemode (websettings.load_cache_else_network);// close webview in cache
Setallowfileaccess (true) // settings can access the file
Setneedinitialfocus (true) //sets the node for WebView when Requestfocus calls WebView Span style= "COLOR: #008000" >
Webview websettings.setbuiltinzoomcontrols (true); // settings support scaling
setjavascriptcanopenwindowsautomatically (true) // supports opening a new window via JS
Setloadwithoverviewmode (TRUE);//Zoom to the size of the screen
Setloadsimagesautomatically ( true) // Supports automatic loading of images
Total solution of 9.WebViewClient method
Doupdatevisitedhistory (WebView view, String URL,Boolean isreload)//(Update history)Onformresubmission (WebView view, message dontresend, message resend)//(Application re-requests web 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 the start of loading the page call, usually we can set a loading in this page, tell the user program is waiting for the network response.
Onpagefinished (WebView view, String URL)//Called at the end of page loading. Similarly, we know that a page loading is complete, so we can close the loading bar, switch the program action.Onreceivederror (WebView view,int ErrorCode, string description, String failingurl)//(Report error message)Onreceivedhttpauthrequest (WebView view, Httpauthhandler handler, String host,string Realm)//(Get Return information authorization request)Onreceivedsslerror (WebView view, Sslerrorhandler handler, sslerror error)//Overriding this method allows WebView to handle HTTPS requests.Onscalechanged (WebView view,float Oldscale, float newscale) // (called when WebView changes) onunhandledkeyevent (WebView view, KeyEvent Event) //(called when the key event is not loaded) shouldoverridekeyevent (WebView view, keyevent event)// Override this method to handle key events in the browser. shouldoverrideurlloading (WebView view, String URL) // Click on the request is the link is not called, Overriding this method returns true to indicate that clicking a link inside a webpage or jumping in the current webview does not jump to the browser. This function we can do a lot of things, such as we read to some special URL, so we can not open the address, cancel the operation, for the pre-defined other operations, which is very necessary for a program.
Android WebView Use detailed