Android編程實(shí)現(xiàn)WebView添加進(jìn)度條的方法
本文實(shí)例講述了Android編程實(shí)現(xiàn)WebView添加進(jìn)度條的方法。分享給大家供大家參考,具體如下:
標(biāo)準(zhǔn)的XML界面
<?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" > <ProgressBar android:id="@+id/pb" style="?android:attr/progressBarStyleHorizontal" android:layout_width="fill_parent" android:layout_height="8dip" android:indeterminateOnly="false" android:max="100" android:progressDrawable="@drawable/progress_bar_states" > </ProgressBar> <WebView android:id="@+id/webview" android:layout_width="match_parent" android:layout_height="match_parent" /> </LinearLayout>
上面聲明了兩個控件,一個是progressBar 一個是 webview,progressbar用來顯示webview控件的加載進(jìn)度的
值得注意的是我們重寫的progressdrawable這個屬性,把原來難看的加載條,稍稍美化了一些,下面就是xml代碼:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item android:id="@android:id/background"> <shape> <gradient android:startColor="#ff0000" android:centerColor="#ffa600" android:endColor="#ff5500" /> </shape> </item> <item android:id="@android:id/secondaryProgress"> <clip> <shape> <gradient android:startColor="#234" android:centerColor="#234" android:endColor="#a24" /> </shape> </clip> </item> <item android:id="@android:id/progress"> <clip> <shape> <gradient android:startColor="#33000001" android:centerColor="#40000000" android:endColor="#44000000" /> </shape> </clip> </item> </layer-list>
下面是Activity的java代碼:
ProgressBar pb; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.xxx); pb = (ProgressBar) findViewById(R.id.pb); pb.setMax(100); WebView webView = (WebView) findViewById(R.id.webview); webView.getSettings().setJavaScriptEnabled(true); webView.getSettings().setSupportZoom(true); webView.getSettings().setBuiltInZoomControls(true); webView.setWebChromeClient(new WebViewClient() ); webView.loadUrl("http://www.x.com"); } private class WebViewClient extends WebChromeClient { @Override public void onProgressChanged(WebView view, int newProgress) { pb.setProgress(newProgress); if(newProgress==100){ pb.setVisibility(View.GONE); } super.onProgressChanged(view, newProgress); } }
關(guān)鍵地方是重寫了一個webchromeclient中的onprogressChange方法,這樣我們就能控制progress的進(jìn)度啦,是不是很方便的,京東也是這么干的哦,快去試一試吧
更多關(guān)于Android相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Android視圖View技巧總結(jié)》、《Android開發(fā)動畫技巧匯總》、《Android編程之a(chǎn)ctivity操作技巧總結(jié)》、《Android布局layout技巧總結(jié)》、《Android開發(fā)入門與進(jìn)階教程》、《Android資源操作技巧匯總》及《Android控件用法總結(jié)》
希望本文所述對大家Android程序設(shè)計有所幫助。
- Android中WebView加載網(wǎng)頁設(shè)置進(jìn)度條
- Android自定義帶進(jìn)度條WebView仿微信加載過程
- Android 實(shí)現(xiàn)帶進(jìn)度條的WebView的實(shí)例
- Android中WebView加載網(wǎng)頁設(shè)置進(jìn)度條
- android實(shí)現(xiàn)用戶體驗(yàn)超棒的微信WebView進(jìn)度條
- Android 帶進(jìn)度條的WebView 示例代碼
- Android Webview添加網(wǎng)頁加載進(jìn)度條實(shí)例詳解
- Android WebView線性進(jìn)度條實(shí)例詳解
- Android中實(shí)現(xiàn)Webview頂部帶進(jìn)度條的方法
- Android WebView實(shí)現(xiàn)頂部進(jìn)度條
相關(guān)文章
Android AutoCompleteTextView自動提示文本框?qū)嵗a
這篇文章主要介紹了Android AutoCompleteTextView自動提示文本框?qū)嵗a的相關(guān)資料,非常不錯,具有參考借鑒價值,需要的朋友可以參考下2016-07-07Android實(shí)現(xiàn)3種側(cè)滑效果(仿qq側(cè)滑、抽屜側(cè)滑、普通側(cè)滑)
這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)多種側(cè)滑效果,包括仿qq側(cè)滑,抽屜側(cè)滑,普通側(cè)滑三種效果,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-04-04item高度不同時Recyclerview獲取滑動距離的方法
這篇文章主要介紹了item高度不同時Recyclerview獲取滑動距離的方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-11-11Android實(shí)現(xiàn)截圖分享qq 微信功能
在日常生活中,經(jīng)常用到qq,微信截圖分享功能,今天小編通過本文給大家介紹Android實(shí)現(xiàn)截圖分享qq 微信功能,具體實(shí)現(xiàn)代碼大家參考下本文2017-12-12Android實(shí)現(xiàn)帶磁性的懸浮窗體效果
這篇文章主要介紹了Android實(shí)現(xiàn)帶磁性的懸浮窗體效果,涉及Android針對窗體的動態(tài)操作相關(guān)技巧,具有一定參考借鑒價值,需要的朋友可以參考下2016-07-07Android實(shí)現(xiàn)多點(diǎn)觸摸操作
這篇文章主要介紹了Android實(shí)現(xiàn)多點(diǎn)觸摸操作,實(shí)現(xiàn)圖片的放大、縮小和旋轉(zhuǎn)等處理,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2022-05-05Android組件實(shí)現(xiàn)長按彈出上下文菜單功能的方法
這篇文章主要介紹了Android組件實(shí)現(xiàn)長按彈出上下文菜單功能的方法,結(jié)合實(shí)例形式分析了Android實(shí)現(xiàn)長按彈出上下文菜單的具體步驟與相關(guān)操作技巧,需要的朋友可以參考下2017-07-07