Resource Description:
The 1.android provides a WebView control that is designed to browse the Web.
Then load the WebView control in the program, setting properties such as: color, font, URL to visit, etc. Use the Loadurl method to set the URL that the current webview needs to access. When creating WebView, the system has a default setting, which we can get by webview.getsettings.
2. Here's how to set up some common properties, states
WebSettings common methods:
Setallowfileaccess Enable or disable WebView access to file data
Setblocknetworkimage whether to display network images
Setbuiltinzoomcontrols settings support Scaling
Setcachemode Set buffered mode
Setdefaultfontsize set default font size
Setdefaulttextencodingname set the default encoding to use when decoding
Setfixedfontfamily set the fixed-use font
setjavasciptenabled setting supports JavaScript
Setlayoutalgorithm setting Layout method
setlighttouchenabled settings with mouse activation is selected
Setsupportzoom setting supports zoom
Webviewclient Common methods:
DoUpdate visitedhistory Update History
Onformresubmission application re-requesting Web page data
Onloadresource load the resources provided by the specified address
onpagefinished Page Loading complete
onpagestarted Web page starts loading
Onreceivederror Reporting Error messages
Onscalechanged WebView Change
Shouldoverrideurlloading control The new connection opens in the current WebView
Webchromeclient Common methods:
Onclosewindow Close WebView
Oncreatewindow Creating WebView
Onjsalert Handling the Alert dialog box in JavaScript
Onjsconfirm handling the Confirm dialog box in JavaScript
Onjsprompt handling the prompt dialog box in JavaScript
Onprogresschanged Loading progress bar change
Onreceivedlcon page icon Change
Onreceivedtitle Page Title Change
Onrequestfocus WebView Show Focus
3. Android WebView related knowledge
@ The following code sets the URL that the current WebView needs to access through the Loadurl method:
mwebview= (WebView) Findviewbyid (r.id.webview01);
Mwebview.loadurl ("http://www.sogou.com"); The
@ in Android specifically uses WebSettings to set some properties, states, etc. of WebView. When creating WebView, the system has a default setting that we can use to webview.getsettings to get this setting:
WebSettings websettings=mwebview.getsettings ();// The Get Object
WebSettings and WebView all exist in the same life cycle, and when WebView is destroyed, an exception is thrown if WebSettings is used again.
@ Use Webviewclient to finish customizing the Web browser in your application:
Webviewclient is a class that assists WebView in handling events such as notifications, requests, and so on. The Webviewclient object is specified by WebView's Setwebviewclient method.
WebView can help WebView browse the Web by overriding the Webviewclient method:
Public Boolean shouldoverrideurlloading
(WebView view, String URL) {view. Loadurl (URL); return true;}
4. Android WebView Instance
The instance uses EditText to enter the URL, uses the button to confirm the connection, and displays the Web page content with WebView.
Webviewclient is used here to assist webview with some events, so the pages we display are in a WebView control. You can set forward and backward through the GoBack and GoForward methods to check if you can go forward and back:
if ((Keycode==keyevent.keycode_back) &&mwebview.cangoback ())
{
Mwebview.goback ()//Return to previous page
return true;
}
example, you access an HTML page that contains a JavaScript dialog box through a home-made browser. By clicking on the "Warning, Reminder Dialog" button on the interface, the "dialog with Selection" button, the "Require user Input Dialog" button, the interface will pop up the dialog box "This is a warning dialog box", "More information please go to my Blog" normal button/Cancel button, "Input Dialog" normal button/Cancel button, A jump page. The Js HTML page is in the root directory of the code package (dialog.html).
We set up a Webchromeclient object for WebView through the Setwebchromeclient method, which assists the webview in processing the JS dialog box, listening for button events, We then pass our operation to JS processing through the confirm and cancel methods.
Package Com.yarin.android.examples_08_06;import Android.app.activity;import Android.app.alertdialog;import Android.app.alertdialog.builder;import Android.content.dialoginterface;import Android.graphics.Bitmap;......public Class Activity01 extends Activity{private final String debug_tag = "Activity01";p rivate button mbutton;private EditText ME Dittext;private WebView mwebview;/** Called when the activity is first created. */@Overridepublic void onCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview ( R.layout.main); Mbutton = (Button) Findviewbyid (r.id.button01); medittext = (EditText) Findviewbyid (r.id.edittext01); Mwebview = (WebView) Findviewbyid (R.ID.WEBVIEW01);//Set support JavaScript script websettings websettings = mwebview.getsettings () ; websettings.setjavascriptenabled (true);//Set can access file Websettings.setallowfileaccess (true);// Setting supports scaling websettings.setbuiltinzoomcontrols (true);//Set Webviewclientmwebview.setwebviewclient (new Webviewclient () { public boolean shouldoverrideurlloading (WEbview view, String URL) {view.loadurl (URL); return true;} @Overridepublic void onpagefinished (WebView view, String URL) {super.onpagefinished (view, URL);} @Overridepublic void onpagestarted (WebView view, String URL, Bitmap favicon) {super.onpagestarted (view, URL, favicon);});
Anaroid WebView Detailed Daquan