Android webview loads local HTML, HTML in the current APK, and remote URL

Source: Internet
Author: User

First, add the webview control to the XML file in the layout folder.

 

<Webview <br/> Android: Id = "@ + ID/wv1" <br/> Android: layout_width = "fill_parent" <br/> Android: layout_height = "fill_parent" <br/>

 

Enter the following in the main file:Code

 

Public class testdemo extends activity {<br/>/** called when the activity is first created. */</P> <p> @ override <br/> Public void oncreate (bundle savedinstancestate) {<br/> super. oncreate (savedinstancestate); <br/> setcontentview (R. layout. main); </P> <p> webview wview = (webview) findviewbyid (R. id. wv1); <br/> websettings Wset = wview. getsettings (); <br/> Wset. setjavascriptenabled (true); </P> <p> // wview. loadurl ("file: // android_asset/index.html"); <br/> // wview. loadurl ("content: // com.android.html fileprovider/sdcard/index.html"); <br/> wview. loadurl ("http://wap.baidu.com"); </P> <p >}< br/>

 

// Wview. loadurl ("File: // android_asset/index.html");

-----Open the index.html file under the assetdirectory of this package
// Wview. loadurl ("content: // com.android.html fileprovider/sdcard/index.html ");

-----Open the SDK index.html File
// Wview. loadurl ("Http://wap.baidu.com");

----- Open the HTML file of the specified URL

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.