Android WebView (i) basic use

Source: Internet
Author: User

WebView is the component that Android uses to load Web pages, and if you want to use this component to load Web pages, you need to add Network permissions:
   <uses-permission android:name= "Android.permission.INTERNET"/>
WebView can be laid out in XML as well as other components:
<webview                android:id= "@+id/webview"                android:layout_width= "fill_parent"                android:layout_height= " Fill_parent "/>
You can also make new out of the code:
WebView webview=new WebView (this);
The code to load the URL is as follows:
Webview.loadurl ("https://www.baidu.com/");
The code for loading the HTML string is as follows:
Webview.loaddatawithbaseurl (NULL, "
Load the local asset file code as follows:

If it is like the URL above to load Baidu, you need to set whether to support JavaScript, if not support JavaScript will start the phone's own browser to load the URL you want to load, otherwise it will load itself. The code to set whether JavaScript is supported is as follows:
WebSettings websettings = Webview.getsettings (); websettings.setjavascriptenabled (true);

WebView can also set the following properties:

Setallowfileaccess Enable or disable WebView access to file data//Setblocknetworkimage whether the network image is displayed//Setbuiltinzoomcontrols setting supports zooming// Setdefaultfontsize Setting the default font size//setdefaulttextencodingname Setting the default encoding used when decoding//setfixedfontfamily setting fixed used font// setjavascriptenabled Settings Support javascript//setlayoutalgorithm set layout mode//setlighttouchenabled settings with mouse activation is selected//Setsupportzoom Sets whether the zoom//Setusewideviewport method setting is supported WebView the recommended window. Whether any scaling//Setloadwithoverviewmode method is possible is to set the mode of WebView loaded pages. setsavepassword//setsaveformdata Save form data//setjavascriptenabled//setrenderpriority//setgeolocationenabled enable geo-targeting Setgeolocationdatabasepath set the location of the database path//Setcachemode Set buffered mode//setdomstorageenabled turn on DOM storage API function//Setdatabas  Eenabled Open Database Storage API function//SetDatabasePath set DB cache path//Websettings.setappcachepath Settings Application Caches cache directory// Websettings.setappcacheenabled Open Application Caches function

The effect of the above load Baidu is as follows:




Android WebView (i) basic use

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.