AndroidManifest.xml文件中加入網絡訪問的權限設置:java
<uses-permission android:name="android.permission.INTERNET" />android
activity.xml代碼web
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="com.jt.http_01.MainActivity" > <WebView android:id="@+id/webView1" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" /> </RelativeLayout>
WebViewLoadURL.java代碼網絡
/** * 使用WebView瀏覽網頁 * @author jiatao * @date 2015-5-2 * @version 1.0 */ package com.jt.http_01; import android.app.Activity; import android.os.Bundle; import android.webkit.WebView; public class WebViewLoadURL extends Activity { private WebView webView; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); initDisplay(); } public void initDisplay() { // TODO Auto-generated method stub webView = (WebView) findViewById(R.id.webView1); String url = "http://www.163.com"; //定義URL地址 /** * 調用loadUrl()方法加載HTML代碼 * public void loadUrl(String url){ } */ webView.loadUrl(url); } }