Android中實(shí)現(xiàn)Webview頂部帶進(jìn)度條的方法
寫這篇文章,做份備忘,簡(jiǎn)單滴展示一個(gè)帶進(jìn)度條的Webview示例,進(jìn)度條位于Webview上面.
示例圖如下:
主Activity代碼:
package com.droidyue.demo.webviewprogressbar;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.widget.ProgressBar;
import com.droidyue.demo.webviewprogressbar.R;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final ProgressBar bar = (ProgressBar)findViewById(R.id.myProgressBar);
final WebView webView = (WebView)findViewById(R.id.myWebView);
webView.setWebChromeClient(new WebChromeClient() {
@Override
public void onProgressChanged(WebView view, int newProgress) {
if (newProgress == 100) {
bar.setVisibility(View.INVISIBLE);
} else {
if (View.INVISIBLE == bar.getVisibility()) {
bar.setVisibility(View.VISIBLE);
}
bar.setProgress(newProgress);
}
super.onProgressChanged(view, newProgress);
}
});
findViewById(R.id.myButton).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
webView.reload();
}
});
final String url = "http://jb51.net";
webView.loadUrl(url);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
布局文件代碼
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<Button
android:id="@+id/myButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Reload"
/>
<ProgressBar
style="?android:attr/progressBarStyleHorizontal"
android:id="@+id/myProgressBar"
android:layout_below="@id/myButton"
android:layout_width="match_parent"
android:layout_height="5px"
/>
<WebView
android:id="@+id/myWebView"
android:layout_below="@id/myProgressBar"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</RelativeLayout>
不要忘記在Mainfest加入使用網(wǎng)絡(luò)權(quán)限喲.
<uses-permission android:name="android.permission.INTERNET"/>
實(shí)現(xiàn)很簡(jiǎn)單,沒(méi)什么技術(shù)含量.備忘而已.
關(guān)于如何自定義進(jìn)度條請(qǐng)參考:http://www.dbjr.com.cn/article/59978.htm
- Android 七種進(jìn)度條的樣式
- android自定義進(jìn)度條漸變色View的實(shí)例代碼
- Android文件下載進(jìn)度條的實(shí)現(xiàn)代碼
- Android編程之ProgressBar圓形進(jìn)度條顏色設(shè)置方法
- android ListView和ProgressBar(進(jìn)度條控件)的使用方法
- Android中自定義進(jìn)度條詳解
- Android實(shí)現(xiàn)進(jìn)度條(ProgressBar)的功能與用法
- 實(shí)例詳解Android自定義ProgressDialog進(jìn)度條對(duì)話框的實(shí)現(xiàn)
- android中實(shí)現(xiàn)OkHttp下載文件并帶進(jìn)度條
- Android自定義View實(shí)現(xiàn)進(jìn)度條動(dòng)畫
相關(guān)文章
Flutter中跨組件數(shù)據(jù)傳遞的方法總結(jié)
Flutter中的數(shù)據(jù)傳遞一般包括:父->子,子->父,父->父,也就是說(shuō)嵌套時(shí)的傳遞以及跨頁(yè)面的傳遞,本文整理了三種我們通常使用的方法,需要的可以參考一下2023-06-06解析Android開(kāi)發(fā)優(yōu)化之:對(duì)界面UI的優(yōu)化詳解(三)
本篇文章主要討論一下復(fù)雜界面中常用的一種技術(shù)——界面延遲加載技術(shù)2013-05-05Android studio 混淆+打包+驗(yàn)證是否成功
本文主要介紹了Android studio 混淆+打包+驗(yàn)證是否成功的相關(guān)知識(shí),具有很好的參考價(jià)值。下面跟著小編一起來(lái)看下吧2017-03-03深入了解Android Okio的超時(shí)機(jī)制
Okio是一個(gè)IO庫(kù),底層基于Java原生的輸入輸出流實(shí)現(xiàn)。但原生的輸入輸出流并沒(méi)有提供超時(shí)的檢測(cè)機(jī)制。而Okio實(shí)現(xiàn)了這個(gè)功能,本文就來(lái)為大家詳細(xì)講講2023-02-02Android動(dòng)態(tài)加載布局實(shí)現(xiàn)技巧介紹
通過(guò)使用LayoutInflater 每次點(diǎn)擊按鈕時(shí)候去讀取布局文件,然后找到布局文件里面的各個(gè)VIEW 操作完VIEW 后加載進(jìn)我們setContentView 方面里面的要放的布局文件里面,每次動(dòng)態(tài)加載文件必需調(diào)用 removeAllViews方法,清除之前的加載進(jìn)來(lái)的View2022-12-12Android編程實(shí)現(xiàn)popupwindow定時(shí)消失的方法
這篇文章主要介紹了Android編程實(shí)現(xiàn)popupwindow定時(shí)消失的方法,結(jié)合實(shí)例形式分析了Android使用定時(shí)器實(shí)現(xiàn)popupwindow定時(shí)消失的相關(guān)操作技巧,需要的朋友可以參考下2018-01-01Android?ScrollView實(shí)現(xiàn)滾動(dòng)超過(guò)邊界松手回彈
這篇文章主要為大家詳細(xì)介紹了Android?ScrollView實(shí)現(xiàn)滾動(dòng)超過(guò)邊界松手回彈,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-04-04Android實(shí)現(xiàn)簡(jiǎn)易的計(jì)算器
這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)簡(jiǎn)易的計(jì)算器,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-10-10