WebView Study Notes

Source: Internet
Author: User

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

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.