android webview summary

What is webview?

 

A View that displays web pages. This class is the basis upon which you can roll your own web browser or simply display some online content within your Activity. It uses the WebKit rendering engine to display web pages and includes methods to navigate forward and backward through a history, zoom in and out, perform text searches and more.

 

How to use webview?

 

1. in order for your Activity to access the Internet and load web pages in a WebView, you must add the INTERNET permissions to your Android Manifest file:

<uses-permission
 
android:name
=
"android.permission.INTERNET"
 
/>

This must be a child of the <manifest> element.

 2.define EditText, ImageButton and webview in layout, as:

<EditText
    android:id="@+id/myEditText1"
    android:layout_width="267px"
    android:layout_height="40px"
    android:textSize="18sp"
    android:layout_x="5px"
    android:layout_y="32px"/>
<ImageButton
    android:id="@+id/myImageButton1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/white"
    android:src="@drawable/go"
    android:layout_x="275px"
    android:layout_y="35px"/>
<WebView
    android:id="@+id/myWebView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_x="7px"
    android:layout_y="90px"
    android:background="@drawable/black"
    android:focusable="true"/>

3.handle the click event and call loadurl of webview:

String strURI = mEdtText.getText().toString();

if(URLUtil.isNetworkUrl(strURI))
 {
            mWebView.loadUrl(strURI);

            Toast.makeText(webTest.this, getString(R.string.load)+strURI, Toast.LENGTH_LONG).show();

}

4. if u want to suppor ajax, please refer to websettings,

WebSettings weSettings = mWebView.getSettings();
 weSettings.setJavaScriptEnabled(true);

 

 

         The webview may call the default web browser in the android emulator or device, for example, if u input url(http://www.baidu.com/), nothing will be displayed in webview, re-directed to default web browser. But with url(http://m9.baidu.com/), it will display the web page.

Click the link in the page, it will direct to default web browser, not decided by _blank target in the <a href>.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值