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>.