现在很多项目都是混合开发,在webview加载网页时,为了提高用户体验,需要给用户展示网页的加载进度,因此在webview中加入进度条显示加载进度,还有一个就是很多H5并没有写自己的返回键,很多时候需要安卓这边写返回键返回上一层网页或者是退出webview所在activity。
运行效果如下:
1、webview所在activity布局:
<?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" >
<include layout="@layout/web_title_bar" />
<ProgressBar
android:id="@+id/progressBar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="3dp"
android:layout_below="@+id/web_title_bar"
android:progressDrawable="@drawable/pg"
android:visibility="gone"
<!--ProgressBar设置只有在加载过程中才会显示,所以初始状态是gone-->
/>
<WebView
android:id="@+id/webView"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_below="@id/progressBar"/>
</LinearLayout></