Android-webview usage

Source: Internet
Author: User

To change the project to the Android version, use the webview class:

1. You must configure the following in androidmanifest. xml:

The purpose is to allow the control to access browser resources.

  </activity>            </application>    <uses-permission android:name="android.permission.INTERNET" />

2. configure a webview (layout folder, Main. XML) in the configuration file you want to load ):

<TextView        android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:text="@string/hello" />    <WebView         android:id="@+id/WebView01"        android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:text="@string/webview"        />

3. The logic code is as follows:

Private webview;
Private string url = "file: // android_asset/show.html ";
// The show.html file must be placed in the asset directory of the project file
// URL = "content: // com.android.html fileprovider/sdcard/index.html ";
-----Open the SDK index.html File
// URL = ("http://wap.baidu.com );
----- Open the HTML file of the specified URL
.
.
.
Webview = (webview) findviewbyid (R. Id. webview01); webview. getsettings (). setjavascriptenabled (true); webview. loadurl (URL );

4. other methods to access the Web or resources:

Access through URL directly:

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

2. Use textview to display HTML

Textview text1 = (textview) findviewbyid (R. Id. textview02); text1.settext (html. fromhtml ("<font size = '20'> webpage content </font> "));
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.