Can be easily understood as a component, as with Button edittext.
As an example:
Main function:
Package Com.example.webviewdemo;import Android.app.activity;import Android.os.bundle;import Android.view.View; Import Android.view.view.onclicklistener;import Android.webkit.webview;import Android.webkit.webviewclient;import Android.widget.button;import Android.widget.edittext;public class Mainactivity extends Activity {private Button start; Private EditText address;p rivate WebView web = null; @Overrideprotected void OnCreate (Bundle savedinstancestate) {SUPER.O Ncreate (savedinstancestate); Setcontentview (r.layout.activity_main); this.web = (WebView) Findviewbyid (R.id.webview ); this.address = (EditText) Findviewbyid (r.id.address); This.start = (Button) Findviewbyid (R.id.start); This.start.setOnClickListener (New Onclicklistener () {@Overridepublic void OnClick (View v) {//TODO auto-generated Method stubstring str = Address.gettext (). toString (); Web.setwebviewclient (new Webviewclient ()); Web.getsettings (). Setjavascriptenabled (TRUE); Allow JavaScript script to run Web.loadurl ("http://" +STR);}});}}
Layout:
<linearlayout xmlns:android= "http://schemas.android.com/apk/res/android" xmlns:tools= "http// Schemas.android.com/tools " android:layout_width=" match_parent " android:orientation=" vertical " android:layout_height= "Match_parent" tools:context= "com.example.webviewdemo.MainActivity" > < EditText android:id= "@+id/address" android:layout_width= "fill_parent" android:hint= "Enter URL here" android:layout_height= "Wrap_content"/> <button android:id= "@+id/start" android:layout_ Width= "Wrap_content" android:layout_height= "wrap_content" android:text= "open page"/> <webview android:id= "@+id/webview" android:layout_width= "fill_parent" android:layout_height= "Wrap_ Content " android:layout_margintop=" 10DP " android:layout_weight=" 1 "/> </LinearLayout>
Permission statement:
<uses-permission android:name= "Android.permission.INTERNET"/>
Run the diagram as follows
Common settings (webview.getsettings () call) go from Code-pig, original address
Click to open link
< Strong> setjavascriptenabled (Boolean flag) |
Set whether JavaScript is supported |
< Strong> setdefaultfontsize (int size) |
sets the default font size |
< Strong> Setdefaulttextencodingname (String encoding) |
sets the encoding of default characters |
< Strong> Setallowfileaccess (Boolean Allow): |
sets whether to allow access to file data |
Setdatabaseenabled (Boolean flag)
|
Set whether database-related APIs can be used
|
SetDatabasePath (String DatabasePath) |
If you use the database API, this method specifies the path to the database file |
Setblocknetworkimage (Boolean flag) |
Sets whether to suppress the display of pictures, true to suppress pictures |
Setsavepassword (Boolean Save) |
Set whether to save password |
Settextize (Websetting.textsize) |
Set page text size |
Setsupportzoom (Bollean support) |
Set whether Zoom is supported |
WebView Study Notes