wKioL1Qjtm3CHPWPAAEJyRaAG04153.jpg

1、编写界面

   

    <WebView

        android:id="@+id/webview"

        android:layout_width="match_parent"

        android:layout_height="match_parent" />


2、申请权限    


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


3、MainActivity.java


package com.malakana.webview;


import android.os.Bundle;

import android.annotation.SuppressLint;

import android.app.Activity;

import android.webkit.WebView;

import android.webkit.WebViewClient;


public class MainActivity extends Activity {


@SuppressLint("SetJavaScriptEnabled")

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

WebView webview = (WebView) findViewById (R.id.webview);

webview.getSettings().setJavaScriptEnabled(true);  //使能JavaScript

webview.setWebViewClient(new WebViewClientDemo());

//webview.loadUrl("http://www.sina.com.cn");  //加载网页

webview.loadUrl("http://www.nuc.edu.cn/");

}

private class WebViewClientDemo extends WebViewClient

{

public boolean shouldOverrideUrlLoading(WebView view,String url)

{

view.loadUrl(url);  //在 WebView中而不是调用系统浏览器  浏览网页

return true;

}

}

}