Android開發模板------WebView載入時顯示ProgressBar進度條,android載入webview

來源:互聯網
上載者:User

Android開發模板------WebView載入時顯示ProgressBar進度條,android載入webview

ProgressBar進度條不能完全填充控制項,這讓我糾結了很久。

後來ProgressBar添加了一個屬性android:progressDrable解決了。

1、首先看下該布局:

<ProgressBar     android:id="@+id/myProgressBar"    style="?android:attr/progressBarStyleHorizontal"    android:layout_below="@id/control_search_bar"    android:layout_gravity="center_vertical"    android:visibility="invisible"    android:progressDrawable="@drawable/progressbar"    android:layout_width="match_parent"    android:layout_height="2dp"/>

2、progressbar.xml位於drawable檔案夾下:

<?xml version="1.0" encoding="utf-8"?><layer-list xmlns:android="http://schemas.android.com/apk/res/android" >    <item android:id="@android:id/progress">        <clip>            <shape>                <corners android:radius="2dip" />                <gradient                    android:angle="0"                    android:endColor="#8000ff00"                    android:startColor="#80ff0000" />            </shape>        </clip>    </item></layer-list>
該檔案可以設定你自己想要的樣式,下面是參考網上樣式:

<?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="2dip" />            <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="2dip" />                <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="2dip" />                <gradient                    android:angle="0"                    android:endColor="#8000ff00"                    android:startColor="#80ff0000" />            </shape>        </clip>    </item></layer-list>
3、ProgressBar主要是在WebChromeClient使用:

private class MyWebChromeClient extends WebChromeClient {@Overridepublic void onProgressChanged(WebView view, int newProgress) {myProgressBar.setMax(100);if (newProgress < 100) {if (myProgressBar.getVisibility() == View.INVISIBLE) {myProgressBar.setVisibility(View.VISIBLE);}myProgressBar.setProgress(newProgress);} else {myProgressBar.setProgress(100);myProgressBar.setVisibility(View.INVISIBLE);}super.onProgressChanged(view, newProgress);}}

寫完,收工!

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.