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
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->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->HelloWebViewAndroid->Android Application 显示图片如下:

本文介绍了一个简单的Android应用示例,该应用使用WebView组件加载网页。通过示例代码展示了如何创建一个可以浏览网页的基本活动。
3719

被折叠的 条评论
为什么被折叠?



