webview添加仿微信横向加载进度条(渐变色)

progressbar使用

 <FrameLayout
            android:id="@+id/fl_video"
            android:layout_width="match_parent"
            android:layout_height="match_parent">
            <wendu.dsbridge.DWebView
                android:id="@+id/webView"
                android:layout_width="match_parent"
                android:layout_height="match_parent"></wendu.dsbridge.DWebView>
            <ProgressBar
                android:id="@+id/progress"
                style="@style/Widget.AppCompat.ProgressBar.Horizontal"
                android:layout_width="match_parent"
                android:layout_height="5dp"
                android:progress="0"
                android:progressDrawable="@drawable/progressbar"
                android:indeterminateTintMode="src_atop"
                android:indeterminateTint="@android:color/holo_blue_light"
                android:max="100">

            </ProgressBar>

        </FrameLayout>

自定义progressbar颜色

<?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="5dip" />

            <gradient
                android:angle="0"
                android:centerColor="#ff5a5d5a"
                android:centerY="0.75"
                android:endColor="#ff747674"
                android:startColor="#ff9d9e9d" />
        </shape>
    </item>

    <item android:id="@android:id/secondaryProgress">

        <clip>

            <shape>

                <corners android:radius="5dip" />

                <gradient
                    android:angle="0"
                    android:centerColor="#80ffb600"
                    android:centerY="0.75"
                    android:endColor="#a0ffcb00"
                    android:startColor="#80ffd300" />
            </shape>
        </clip>
    </item>

    <item android:id="@android:id/progress">
      <clip>
          <shape>
              <corners android:radius="3dp"></corners>
              <gradient
                  android:angle="0"
                  android:startColor="#27FDFF"
                  android:endColor="#3756FF"/>


          </shape>
      </clip>
  </item>

</layer-list>

webview中在WebChromeClient监听进度条

private class MyWebChromeClient extends WebChromeClient {
     
        @Override
        public void onProgressChanged(WebView view, int newProgress) {
            int currentProgress = view.getProgress();
            Log.e(TAG, "onProgressChanged: " + newProgress +"/"+ currentProgress);

            super.onProgressChanged(view, newProgress);

            if (newProgress == 100){
                progress.setVisibility(View.GONE);
                if (smartrefresh != null) {
                    smartrefresh.finishRefresh();
                }
            }else {
                progress.setVisibility(View.VISIBLE);
                progress.setProgress(newProgress);
            }
        }
    }
发布了316 篇原创文章 · 获赞 63 · 访问量 37万+

猜你喜欢

转载自blog.csdn.net/ytfunnysite/article/details/102709432