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