WebView是一个开放的浏览器组件,基于WebKit内核开发出来的,在Android系统中,默认提供给了我们WebView组件的支持,我们可以直接使用WebView组件显示网页的内容。
下面是一个简单的Demo,使用的是loadUrl()方法,要求在()中输入URL地址(如www.baidu.com),单击浏览后即可将指定的URL加载到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">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="@+id/open"
android:layout_width="wrap_content