Android ApiDemos example resolution (198): Views-& gt; WebView

Source: Internet
Author: User

This example introduces the simplest usage of WebView and shows HTML links. In fact, WebView has more functions than that. You can basically use WebView to implement your own browser.

WebView uses WebKit to implement front-flip, back, zoom in, zoom out, and search for webpages. To enable the built-in zoom control, you can call WebSettings. setBuiltInZoomControls (boolean ).

In addition, if WebView needs to access the Internet, you need to add INTERNET permissions in AndroidManifest. xml:

<Uses-permission android: name = "android. permission. INTERNET"/>

Basic usage:

By default, WebView does not provide a UI similar to Browser, does not support JavaScript, and ignores web page errors. If you only want to display HTML documents, this default setting is sufficient, however, to support user interaction, you can use the URL to start the Android browser.


[Java]
Uri uri = Uri. parse ("http://www.example.com ");
Intent intent = new Intent (Intent. ACTION_VIEW, uri );
StartActivity (intent );

Uri uri = Uri. parse ("http://www.example.com ");
Intent intent = new Intent (Intent. ACTION_VIEW, uri );
StartActivity (intent );

In this example, a WebView HTML link is displayed:

 

[Java]
SetContentView (R. layout. webview_1 );
 
Final String mimeType = "text/html ";
Final String encoding = "UTF-8 ";
 
WebView wv;
 
Wv = (WebView) findViewById (R. id. wv1 );
Wv. loadData ("<a href = 'X'> Hello World! -1 </a> ", mimeType, encoding );
...

SetContentView (R. layout. webview_1 );

Final String mimeType = "text/html ";
Final String encoding = "UTF-8 ";

WebView wv;

Wv = (WebView) findViewById (R. id. wv1 );
Wv. loadData ("<a href = 'X'> Hello World! -1 </a> ", mimeType, encoding );
...

 

 

 

 

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.