Android WebView的使用方法
Android app打開H5頁一般要實(shí)現(xiàn)如下需求:
1、打開指定url網(wǎng)頁;
2、點(diǎn)擊鏈接可以跳轉(zhuǎn)到下一頁,并更新標(biāo)題;
3、按back鍵或左箭頭可以返回上一頁;
4、當(dāng)webview顯示的是第一級(jí)url時(shí), 按返回鍵或左箭頭關(guān)閉當(dāng)前界面;
5、WebView如何傳值給android, 例如使用H5登錄成功后返回姓名、token等等字段。
6、支持JavaScript, 支持顯示js對(duì)話框。
7、無網(wǎng)絡(luò)時(shí)顯示默認(rèn)布局, 以提高用戶體驗(yàn)。
8、避免WebView的內(nèi)存泄漏。
不多說, 看下面代碼如何實(shí)現(xiàn)上述功能。
參考布局:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:my="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/activity_main_bg" android:orientation="vertical"> <com.eloancn.borrower.common.widget.TitleView android:id="@+id/titleView" android:layout_width="match_parent" android:layout_height="50dp" my:titleText="H5" /> <RelativeLayout android:id="@+id/rl_webViewContainer" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <!--在代碼中添加webView防止內(nèi)存泄露隱患--> <LinearLayout android:id="@+id/neterror_tip" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center_horizontal" android:visibility="gone"> <ImageView android:layout_marginTop="110dp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/not_found" /> </LinearLayout> </RelativeLayout> </LinearLayout>
新聞標(biāo)題:AndroidWebView的使用方法總結(jié)-創(chuàng)新互聯(lián)
URL鏈接:http://chinadenli.net/article4/dgpcie.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供定制網(wǎng)站、外貿(mào)建站、營銷型網(wǎng)站建設(shè)、外貿(mào)網(wǎng)站建設(shè)、網(wǎng)站維護(hù)、品牌網(wǎng)站制作
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容