是个传颂厨

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

跟intent功能差别好像一样吧我也不知道。。。

首先去AndroidMainfest修改权限,加入网络访问权限

<uses-permission android:name="android.permission.INTERNET"/>

在layout中加入webView

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
    <WebView 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/webView"
        />

</LinearLayout>

然后去主文件修改

package com.example.deemo;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebView;
import android.widget.Button;

public class MainActivity extends Activity{
    
    private String url="http://www.bilibili.com";//地址
    private WebView webView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
//        Uri uri = Uri.parse(url);//链接地址
//        Intent intent = new Intent(Intent.ACTION_VIEW,uri);//上文文件和下文目标
//        startActivity(intent);//进行转跳
        init();//执行方法
        }
    
    //构造方法
    private void init() {
        // TODO Auto-generated method stub
        webView=(WebView) findViewById(R.id.webView);
        //本地资源webView.loadUrl(file:///android_asset/文件名)
        webView.loadUrl(url);//打开外部
    }
}

 

posted on 2016-07-31 12:17  是个传颂厨  阅读(345)  评论(0编辑  收藏  举报