Android webview加载进度条

不多说什么了!上代码吧!很简单的东西


首先在定义一个进度条的加载时的两种颜色一个xml文件


<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>  


布局文件

<?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/comm_tit"></include>
    <ProgressBar
        android:id="@+id/progressBar"
        style="?android:attr/progressBarStyleHorizontal"
        android:layout_width="match_parent"
        android:layout_height="3dip"
        android:progressDrawable="@drawable/pg"
        android:visibility="gone"

        />
    <View
        android:layout_width="match_parent"
        android:layout_height="0.1dp"
        android:background="@color/line"></View>
    <WebView
        android:id="@+id/webview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"></WebView>

</LinearLayout>


监听方法及实现过程


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

                if(newProgress==100){
		//执行加载任务完成,隐藏该控件
                    pg1.setVisibility(View.GONE);
                }
                else{
		//开始加载网页时显示进度条以及设置进度值
pg1.setVisibility(View.VISIBLE); pg1.setProgress(newProgress); } } });




//这个问题也是今天有个朋友忽然问我,然后翻了翻之前的项目,不太懂得朋友可以直接留言咨询

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值