WebView 使用指南
webview的基本使用
webview继承自AbsoluteLayout,展示网页的同时,也可以在其中放入其他的子View。
简单的网页展示:
<?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">
<WebView
android:id="@+id/web_view"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
Activity 中的onCreate中
String url = "https://www.baidu.com/";
WebView webView = (WebView) findViewById(R.id.web_view);
webView.loadUrl(url);
这样就可以打开网页了。淡然这只会打开静态的展示页面。如果要顺畅执行整个H5页面我们还需要一些其他的设置。比如,你需要网络权限
<uses-permission android:name="android.permission.INTERNET"/>
webview 方法讲解和属性设置
如果你要详细的了解 webview 的api相关和属性等的设置可以看下面这篇文章 ,介绍的比较系统。WebView·开车指南