Android webview 顶部ProgressBar

xml的代码: <ProgressBar
        android:id="@+id/pb"
        style="?android:attr/progressBarStyleHorizontal"
        android:layout_width="fill_parent"
        android:layout_height="5dip"
        android:indeterminateOnly="false"
        android:max="100"
        android:progressDrawable="@drawable/progress"
        android:visibility="gone" >

    </ProgressBar>


progress的代码:



<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >


    <item android:id="@android:id/background">
        <shape>
            <corners android:radius="2dp" />
            <gradient
                android:angle="270"
                android:centerColor="#E3E3E3"
                android:endColor="#E6E6E6"
                android:startColor="#C8C8C8" />
        </shape>
    </item>
    <item android:id="@android:id/progress">
        <clip>
            <shape>
                <corners android:radius="2dp" />
                <gradient
                    android:centerColor="#4AEA2F"
                    android:endColor="#31CE15"
                    android:startColor="#5FEC46" />
                
            </shape>
        </clip>
    </item>


</layer-list>



Activity中代码:

mWebView.setWebChromeClient(new WebChromeClient(){
@Override
public void onProgressChanged(WebView view, int newProgress) {
// TODO 自动生成的方法存根

if(newProgress==100){
pb_normal.setVisibility(View.GONE);//加载完网页进度条消失
}
else{
pb_normal.setVisibility(View.VISIBLE);//开始加载网页时显示进度条
pb_normal.setProgress(newProgress);//设置进度值
}

}
});



猜你喜欢

转载自blog.csdn.net/qq_33209777/article/details/80902074