学习日记--WebView的简单测试

来源:互联网 发布:步进电机c语言控制程序 编辑:程序博客网 时间:2024/05/01 00:09

加载WebView的方法不难,简单实现只需要三步:

1、在layout布局文件里添加一个WebView:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="match_parent"    tools:context="com.hxzy.webview.MainActivity" >    <WebView        android:id="@+id/webView"        android:layout_width="match_parent"        android:layout_height="match_parent" /></RelativeLayout>

2、java代码,只需要三行

package com.hxzy.webview;import android.app.Activity;import android.os.Bundle;import android.webkit.WebView;public class MainActivity extends Activity {@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);WebView webView = (WebView) findViewById(R.id.webView);String url = "http://www.baidu.com";webView.loadUrl(url);}}

3、添加网络权限

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


0 0
原创粉丝点击