Lập trình Android: Tạo WebView potx

3 424 1
Lập trình Android: Tạo WebView potx

Đang tải... (xem toàn văn)

Thông tin tài liệu

Trung tâm Tin học – ĐH KHTN 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: 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" /> <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" /> Lập trình Android – http://laptrinhdidong.vn Page 1 Trung tâm Tin học – ĐH KHTN <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: Lập trình Android – http://laptrinhdidong.vn Page 2 Trung tâm Tin học – ĐH KHTN Cá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 ^^ Lập trình Android – http://laptrinhdidong.vn Page 3 . ĐH KHTN 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: WebViewDemo Package. 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: Lập trình Android – http://laptrinhdidong.vn. package="com.sample.WebViewDemo" android:versionCode="1" android:versionName="1.0"> <uses-sdk android:minSdkVersion="13" /> <uses-permission android:name="android.permission.INTERNET"

Ngày đăng: 07/08/2014, 09:22

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan