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 );
...