Android Development Practice WebView

Source: Internet
Author: User

Android.webkit.WebView itself is a browser implementation, and its kernel is based on the open source WebKit engine.

Common methods:
void GoBack (): Back
void GoForward (): Forward
void Loadurl (String URL): Load Web page
Boolean zoomin (): Enlarge Web page
Boolean zoomout (): Shrinking Web page

For more information, please refer to the official documentation (DOCS/REFERENCE/ANDROID/WEBKIT/WEBVIEW.HTML)

1. Load the URL corresponding to the page
WebView webview = (WebView) findViewById(R.id.webview);...webview.loadUrl("www.csdn.net");
2. Loading HTML code

WebView provides Loaddatawithbaseurl (string baseUrl, String data, String MimeType, String encoding, String Historyurl) methods, The parameters are described as follows:

baseUrl:作为网页输入的网址(一般null)data:需要加载的HTML代码mimeType:指定HTML代码的MIME类型,HTML可指定为text/htmlencoding:指定HTML代码的字符编码historyUrl:历史输入的网址(一般null)
WebView WebView = (WebView) Findviewbyid (R. ID. WebView);StringBuilder sb = new StringBuilder ();Stitching a piece of HTML code SB. Append(");Sb. Append(");Sb. Append("<title> Test </title>");Sb. Append(");Sb. Append("<body>");Sb. Append(");Sb. Append("</body>");Sb. Append(");Using a simple LoadData method can result in garbled//WebView. LoadData(SB. toString(),"Text/html","Utf-8");Load, and display HTML code WebView. Loaddatawithbaseurl(NULL, SB. toString(),"Text/html","Utf-8", null);
3. Through the WebView and JS interaction

See article: http://blog.csdn.net/smartbetter/article/details/51089613

Android Development Practice WebView

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.