AndroidWebView實現(xiàn)頂部進度條

項目中用到WebView加上進度條放在頂部,讓用戶知道加載進度情況,可以提高用戶體驗:

十余年品牌的成都網站建設公司,超過千家企業(yè)網站設計經驗.價格合理,可準確把握網頁設計訴求.提供定制網站建設、購物商城網站建設、微信小程序、響應式網站開發(fā)等服務,我們設計的作品屢獲殊榮,是您值得信賴的專業(yè)網站設計公司。

效果:

Android WebView實現(xiàn)頂部進度條

布局:

<RelativeLayout

  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:orientation="vertical">
  <WebView
   android:id="@+id/webView"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   android:layout_below="@+id/toolbar_container" />

  <ProgressBar

   android:id="@+id/progressBar"
   
   android:layout_width="match_parent"
   android:layout_height="3dp"
   android:layout_below="@+id/toolbar_container"
   android:background="@drawable/crowd_progressbar_unselect" />

</RelativeLayout>

進度條樣式:

<style name="crowd_item_progressBar">
  <item name="android:indeterminateOnly">false</item>
  <item name="android:progressDrawable">@drawable/crowd_progressbar_background</item>
  <item name="android:minHeight">10dp</item>
  <item name="android:maxHeight">10dp</item>

</style>

進度圖片:

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
 <item
  android:id="@android:id/progress" >
  <clip>
   <shape>
    <solid android:color="@color/selected"/>
    <!--<corners android:radius="1.5dp"/>-->
   </shape>
  </clip>
 </item>
</layer-list>

代碼:

public class WebChromeClient extends android.webkit.WebChromeClient {
  @Override

  public void onProgressChanged(WebView view, int newProgress) {
   if (newProgress == 100) {

    mProgressBar.setVisibility(GONE);
   } else {

    if (mProgressBar.getVisibility() == GONE)
     mProgressBar.setVisibility(VISIBLE);
    mProgressBar.setProgress(newProgress);

   }

   super.onProgressChanged(view, newProgress);

  }

 }

 @Override
 protected void onScrollChanged(int l, int t, int oldl, int oldt) {
  LayoutParams lp = (LayoutParams) mProgressBar.getLayoutParams();
  lp.x = l;
  lp.y = t;
  mProgressBar.setLayoutParams(lp);
  super.onScrollChanged(l, t, oldl, oldt);

 }

}

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持創(chuàng)新互聯(lián)。

當前題目:AndroidWebView實現(xiàn)頂部進度條
轉載注明:http://bm7419.com/article46/gospeg.html

成都網站建設公司_創(chuàng)新互聯(lián),為您提供動態(tài)網站、服務器托管品牌網站設計、網站營銷App開發(fā)、定制開發(fā)

廣告

聲明:本網站發(fā)布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)

網站建設網站維護公司