Tạo webView 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: WebView
Trang 1Tạo webView 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:
<?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"
>
<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" />
Trang 2<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:
Trang 3Các bạn có ý kiến đóng góp vui vòng post lên diễn đàn trang web
www.laptrinhdidong.vn Rất mong nhận được sự góp ý của các bạn Mình sẽ cập nhật diễn đàn thường xuyên ^^