---
title: "Eclipse 开发 Android, Hello, WebView  （学习6）"
author: "llhdf"
date: "2009-11-20T14:27:00Z"
tags: []
slug: "eclipse-android-hello-webview-6"
draft: false
lastmod: "2009-11-20T14:27:44Z"
id: 521204
url: "https://llhdf.iteye.com/blog/521204"
---

# Hello, WebView

A `WebView` allows you to create your own web browser Activity. In this tutorial, we'll create a simple Activity that can view web pages.

 

学习地址：[http://androidappdocs.appspot.com/guide/tutorials/views/hello-webview.html](http://androidappdocs.appspot.com/guide/tutorials/views/hello-webview.html)

 

HelloWebView.java 代码

 

```
package com.example.test;

import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;

public class HelloWebView extends Activity {

	WebView webview;
	
	/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        webview = (WebView) findViewById(R.id.webview);
        webview.getSettings().setJavaScriptEnabled(true);
        webview.loadUrl(http://ditu.google.cn);
        
    }
}
```

 

 

Layout-&gt;main.xml

```
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <WebView 
        android:id="@+id/webview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
    />

</LinearLayout>
```

 

执行 Eclipse-&gt;HelloWebViewAndroid-&gt;Android Application 显示图片如下：

 

 ![](http://dl.iteye.com/upload/attachment/170619/04a52aeb-1eda-33b4-b6f8-842cb595866f.png)

 

[代码下载](http://dl.iteye.com/topics/download/7206ea20-33c8-3336-8571-05a71f410222) [HelloWebView.zip](http://dl.iteye.com/topics/download/7206ea20-33c8-3336-8571-05a71f410222)