最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android編程實現(xiàn)WebView添加進(jìn)度條的方法

 更新時間:2017年02月06日 14:10:25   作者:zzcchunter  
這篇文章主要介紹了Android編程實現(xiàn)WebView添加進(jìn)度條的方法,涉及Android WebView界面及控件功能相關(guān)操作技巧,需要的朋友可以參考下

本文實例講述了Android編程實現(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è)計有所幫助。

相關(guān)文章

最新評論

页游| 克拉玛依市| 徐水县| 商城县| 长泰县| 阿坝县| 嵊州市| 赣州市| 冷水江市| 星座| 岳池县| 宁武县| 克拉玛依市| 红桥区| 闵行区| 壤塘县| 丰原市| 北流市| 临江市| 晴隆县| 固安县| 威海市| 白朗县| 南平市| 石台县| 泸州市| 舟曲县| 喀喇沁旗| 威宁| 安平县| 关岭| 嘉祥县| 蒙自县| 秀山| 辽宁省| 婺源县| 黄浦区| 抚宁县| 嘉义市| 嘉黎县| 桃源县|