Chinaunix首页 | 论坛 | 博客
  • 博客访问: 42316
  • 博文数量: 71
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 726
  • 用 户 组: 普通用户
  • 注册时间: 2014-11-24 08:29
文章分类

全部博文(71)

文章存档

2015年(71)

我的朋友

分类: Android平台

2015-02-20 22:52:28



  1. package com.example.webview;

  2. import android.app.Activity;
  3. import android.content.Intent;
  4. import android.net.Uri;
  5. import android.os.Bundle;
  6. import android.webkit.WebView;

  7. /**
  8.  * @author ECJTU IsayesHu 引言:通过Intent调用系统浏览器// Uri uri =
  9.  * Uri.parse(url);//url是你要链接的地址 //Intent intent = new
  10.  * Intent(Intent.ACTION_VIEW,uri); //startActivity(intent);
  11.  */
  12. public class MainActivity extends Activity {

  13.     private String url = "";
  14.     private WebView webView;

  15.     @Override
  16.     protected void onCreate(Bundle savedInstanceState) {
  17.         super.onCreate(savedInstanceState);
  18.         setContentView(R.layout.web);
  19.         // Uri uri = Uri.parse(url);
  20.         // Intent intent = new Intent(Intent.ACTION_VIEW,uri);
  21.         // startActivity(intent);
  22.         init();
  23.     }

  24.     private void init() {
  25.         webView = (WebView) findViewById(R.id.id_webView);
  26.         // WebView加载本地资源
  27.         // webView.loadUrl("file:///android_asset/example.html");
  28.         // WebView加载web资源
  29.         webView.loadUrl("");
  30.     }
  31. }

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <manifest xmlns:android=""
  3.     package="com.example.webview"
  4.     android:versionCode="1"
  5.     android:versionName="1.0" >

  6.     <uses-sdk
  7.         android:minSdkVersion="8"
  8.         android:targetSdkVersion="21" />
  9.     <uses-permission android:name="android.permission.INTERNET"/>

  10.     <application
  11.         android:allowBackup="true"
  12.         android:icon="@drawable/ic_launcher"
  13.         android:label="@string/app_name"
  14.         android:theme="@style/AppTheme" >
  15.         <activity
  16.             android:name=".MainActivity"
  17.             android:label="@string/app_name" >
  18.             <intent-filter>
  19.                 <action android:name="android.intent.action.MAIN" />

  20.                 <category android:name="android.intent.category.LAUNCHER" />
  21.             </intent-filter>
  22.         </activity>
  23.     </application>

  24. </manifest>

web.xml

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android=""
  3.     android:layout_width="match_parent"
  4.     android:layout_height="match_parent"
  5.     android:orientation="vertical" >

  6.     <WebView
  7.         android:id="@+id/id_webView"
  8.         android:layout_width="match_parent"
  9.         android:layout_height="match_parent" />

  10. </LinearLayout>



阅读(209) | 评论(0) | 转发(0) |
0

上一篇:WebView

下一篇:使用WebView显示网页(二)

给主人留下些什么吧!~~