网站"/>
Android访问百度网站
效果图
逻辑代码--MainActivity
package com.example.week4_day3_web;import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.webkit.WebView;public class MainActivity extends Activity {private WebView web;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);web=(WebView) findViewById(R.id.web);web.loadUrl("/");}@Overridepublic boolean onCreateOptionsMenu(Menu menu) {// Inflate the menu; this adds items to the action bar if it is present.getMenuInflater().inflate(R.menu.main, menu);return true;}}
布局文件
<RelativeLayout xmlns:android=""xmlns: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=".MainActivity" ><WebViewandroid:id="@+id/web"android:layout_width="wrap_content"android:layout_height="wrap_content"/></RelativeLayout>
配置文件--添加网络权限
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android=""package="com.example.week4_day3_web"android:versionCode="1"android:versionName="1.0" ><uses-sdkandroid:minSdkVersion="8"android:targetSdkVersion="18" /><uses-permission android:name="android.permission.INTERNET"/><applicationandroid:allowBackup="true"android:icon="@drawable/ic_launcher"android:label="@string/app_name"android:theme="@style/AppTheme" ><activityandroid:name="com.example.week4_day3_web.MainActivity"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>
更多推荐
Android访问百度网站
发布评论