我们从布局开始:
先定义布局文件main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" 
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<WebView 
android:id="@+id/webview" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" />
</LinearLayout>
</LinearLayout>然后来看java文件:public class AndroidWebViewTest extends Activity {
private WebView webview;
private String url = "http://www.baidu.com/";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
                webview = (WebView) findViewById(R.id.webview);
fillWebView(url);
}private void fillWebView(String url) {
WebSettings webSettings = webview.getSettings();
webSettings.setSavePassword(false);
webSettings.setSaveFormData(false);
webSettings.setJavaScriptEnabled(true);
webSettings.setSupportZoom(false);
webview.setWebChromeClient(new WebChromeClient());
webview.loadUrl(url);
}
}
最后需要注意在AndroidManifest.xml中增加上网权限:
<uses-permission android:name="android.permission.INTERNET" />编译,运行即可。