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·開車指南