Tạo ứng dụng trang WEB
27/07/2012
FacebookTwitterDeliciousStumbleuponDiggMyspaceLinkedInZingmegovnlinkhay


Sau đây mình sẽ demo cách tạo WebView tren môi trường Android như sau: 1/ Tạo 1 project như sau: Project name: WebViewDemo Build Target: Google APIs Application name: WebViewDemo Package name: com.sample.WebViewDemo Create Activity: WebViewDemo 2/ Tạo giao diện trong main.xml như sau:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
androidrientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Web cua toi:"
/>
<WebView
android:id="@+id/web_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1.0"
/>
</LinearLayout>
3/ Thêm vào file WebViewDemoManifest.xml như sau (lưu ý dòng màu vàng):
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.sample.WebViewDemo"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="13" />
<uses-permission android:name="android.permission.INTERNET" />
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".WebViewDemo"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
4/ Code phần WebViewDemo.java như sau:
package com.sample.WebViewDemo;
import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;
public class WebViewDemo extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
WebView webView = (WebView) findViewById(R.id.web_view);
webView.loadUrl("http://laptrinhdidong.vn");
}
}
Cuối cùng, debug ứng dụng như sau: Theo laptrinhdidong