目前很多Android app都內置了可以顯示web頁面的界面,會發現這個界面一般都是由一個叫做WebView的組件渲染出來的,學習該組件可以為你的app開發提升擴展性。
先說下WebView的一些優點:
--可以直接顯示和渲染web頁面,直接顯示網頁
--webview可以直接用html文件(網絡上或本地assets中)作布局
--和JavaScript交互調用
一、基本使用
布局文件:
<LinearLayout 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"
android:orientation="vertical">
<WebView
android:id="@+id/webview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"/>
</LinearLayout>
同時,因為要房訪問網絡,所以manifest中必須要加uses-permission:
<uses-permission android:name="android.permission.INTERNET"/>
在activity中即可獲得webview的引用,同時load一個網址:
webview = (WebView) findViewById(R.id.webView1);
webview.loadUrl(url);
WebView控件之WebSettings詳解:
http://www.lxweimin.com/p/0d7d429bd216
WebView控件之WebViewClient詳解:
http://www.lxweimin.com/p/0c3b11887a13
WebView控件之WebChromeClient詳解:
http://blog.csdn.net/typename/article/details/39495409
WebView控件之文件下載:
http://www.lxweimin.com/p/18bbe7092631
WebView控件之文件上傳(打開圖庫和拍照):
http://www.lxweimin.com/p/2ef9f5a18e5b
webview和js之間的交互:
http://www.lxweimin.com/p/daa689886073
android權限大全:
http://www.cnblogs.com/classic/archive/2011/06/20/2085055.html
WebView使用深入淺出:
http://www.open-open.com/lib/view/open1431569835951.html
通過文件類型打開相似應用程序:
http://www.lxweimin.com/p/4148b2810241
完整工程下載:
http://pan.baidu.com/s/1bpBxJbx