效果图:
第一Activtiy部分
- import android.app.Activity;
- import android.os.Bundle;
- import android.webkit.WebView;
- public class WebViewTest extends Activity {
- private WebView mywebview;
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- mywebview =(WebView)findViewById(R.id.mywebview);
- String strURL = "http://baidu.com";
- mywebview.loadUrl(strURL);
- }
- }
第二部分xml
<?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"
>
<WebView
android:id="@+id/mywebview"
android:layout_height="430px"
android:layout_width="330px"
android:layout_x="7px"
android:layout_y="90px"
android:focusable="false"
/>
</LinearLayout>
第三部分
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.WebViewTest"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".WebViewTest"
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>
<uses-permission android:name="android.permission.INTERNET"/> <!-- 注意添加权限 -->
<uses-sdk android:minSdkVersion="8" />
</manifest>