Android WebView實(shí)現(xiàn)頂部進(jìn)度條
項(xiàng)目中用到WebView加上進(jìn)度條放在頂部,讓用戶知道加載進(jìn)度情況,可以提高用戶體驗(yà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" style="@style/crowd_item_progressBar" android:layout_width="match_parent" android:layout_height="3dp" android:layout_below="@+id/toolbar_container" android:background="@drawable/crowd_progressbar_unselect" /> </RelativeLayout>
進(jìn)度條樣式:
<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>
進(jìn)度圖片:
<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);
}
}
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Android中WebView加載網(wǎng)頁(yè)設(shè)置進(jìn)度條
- Android自定義帶進(jìn)度條WebView仿微信加載過(guò)程
- Android 實(shí)現(xiàn)帶進(jìn)度條的WebView的實(shí)例
- Android中WebView加載網(wǎng)頁(yè)設(shè)置進(jìn)度條
- android實(shí)現(xiàn)用戶體驗(yàn)超棒的微信WebView進(jìn)度條
- Android編程實(shí)現(xiàn)WebView添加進(jìn)度條的方法
- Android 帶進(jìn)度條的WebView 示例代碼
- Android Webview添加網(wǎng)頁(yè)加載進(jìn)度條實(shí)例詳解
- Android WebView線性進(jìn)度條實(shí)例詳解
- Android中實(shí)現(xiàn)Webview頂部帶進(jìn)度條的方法
相關(guān)文章
android實(shí)現(xiàn)雙日期選擇控件(可隱藏日,只顯示年月)
本篇文章主要介紹了android實(shí)現(xiàn)雙日期選擇控件(可隱藏日,只顯示年月) ,非常具有實(shí)用價(jià)值,需要的朋友可以參考下。2017-01-01
Android Activity跳轉(zhuǎn)動(dòng)畫效果
這篇文章主要介紹了Android Activity跳轉(zhuǎn)動(dòng)畫效果,本文圖文并茂給大家介紹的非常詳細(xì),需要的朋友可以參考下2017-02-02
Android 自定義標(biāo)題欄 顯示網(wǎng)頁(yè)加載進(jìn)度的方法實(shí)例
Android 自定義標(biāo)題欄 顯示網(wǎng)頁(yè)加載進(jìn)度的方法實(shí)例,需要的朋友可以參考一下2013-06-06
Android對(duì)話框AlertDialog與DatePickerDialog及TimePickerDialog使用詳解
這篇文章主要介紹了Android對(duì)話框中的提醒對(duì)話框AlertDialog、日期對(duì)話框DatePickerDialog、時(shí)間對(duì)話框TimePickerDialog使用方法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧2022-09-09
Android彈出dialog后無(wú)法捕捉back鍵的解決方法
這篇文章主要為大家詳細(xì)介紹了Android彈出dialog后無(wú)法捕捉back鍵的解決方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-09-09
Android用SharedPreferences實(shí)現(xiàn)登錄注冊(cè)注銷功能
這篇文章主要為大家詳細(xì)介紹了Android用SharedPreferences實(shí)現(xiàn)登錄注冊(cè)注銷功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-04-04
android實(shí)現(xiàn)切換日期左右無(wú)限滑動(dòng)效果
本篇內(nèi)容給大家分享了android開發(fā)時(shí)候?qū)崿F(xiàn)自定義的日期無(wú)限左右滑動(dòng)效果以及控件使用的技巧。2017-11-11
解決Android studio模擬器啟動(dòng)失敗的問(wèn)題
這篇文章主要介紹了Android studio模擬器啟動(dòng)失敗的問(wèn)題及解決方法,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-03-03
詳解用RxJava實(shí)現(xiàn)事件總線(Event Bus)
本篇文章主要介紹了用RxJava實(shí)現(xiàn)事件總線(Event Bus),小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-11-11

