當前位置:首頁 » 安卓系統 » progressbarandroid

progressbarandroid

發布時間: 2023-01-22 06:58:40

⑴ 關於Android怎麼改變ProgressBar進度條顏色

需求:下載中的顏色要自定義,要替換為另外的一個顏色

方法:就是在

<ProgressBar
android:layout_weight="1"
android:id="@+id/download_item_progressBar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="wrap_content"
android:layout_height="15dip"
android:progressDrawable="@drawable/progressbar_style"></ProgressBar>

在drawable中新建一個progressBar_style.xml文件,

這個屬性進行設置,有兩個方案:

第一,設置兩張圖片:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="">

<item android:id="@android:id/background"
android:drawable="@drawable/progressbar_not" />

<item android:id="@android:id/secondaryProgress"
android:drawable="@drawable/progressbar_not">
</item>

<item android:id="@android:id/progress"
android:drawable="@drawable/progressbar_selected">

</item>
</layer-list>

第二種,設置背景顏色:

<?xml version="1.0" encoding="utf-8"?>
<item android:id="@android:id/background"

>

<shape>

<corners android:radius="5dip" />

<gradient

android:startColor="#666666"

android:centerColor="#666666"

android:centerY="0.75"

android:endColor="#666666"

android:angle="270"

/>

</shape>

</item>

<item android:id="@android:id/progress"

>

<clip>

<shape>

<corners android:radius="5dip" />

<gradient

android:startColor="#da1f3e"

android:centerColor="#da1f3e"

android:centerY="0.75"

android:endColor="#da1f3e"

android:angle="270"

/>

</shape>

</clip>

</item>

<item android:id="@android:id/secondaryProgress"

>

<clip>

<shape>

<corners android:radius="5dip" />

<gradient

android:startColor="#fed7ec"

android:centerColor="#fed7ec"

android:centerY="0.75"

android:endColor="#fed7ec"

android:angle="270"

/>

</shape>

</clip>

</item>

</layer-list>

其中的屬性還要進一步研究具體作用,據文檔翻譯有設置角度,漸變的。
轉載,僅供參考。

⑵ android的Progressbar怎麼用

在windows7操作系統Android studio中按照如下步驟使用Progressbar。

1、使用Android studio創建一個android 項目,如下圖:

⑶ Android中ProgressBar百分比怎麼設置小數

SeekBar是progressbar的子類,最小值默認就是0,表示的意義就是進度完成的百分比,如果你要是表示負數值的話可以做一個轉化就行了,比如你可以設置seekbar的取值【0~200】,然後用getValue()減去100就可以表示【-100~100】

⑷ android的Progressbar怎麼用

代碼舉例如下:

//ProgressBar
protectedstaticfinalintSTOP=0x10000;
protectedstaticfinalintNEXT=0x10001;

privateintiCount=0;

rectangleProgressBar.setVisibility(View.VISIBLE);
circleProgressBar.setVisibility(View.VISIBLE);

rectangleProgressBar.setMax(100);
rectangleProgressBar.setProgress(0);
circleProgressBar.setProgress(0);

//創建一個線程,每秒步長為5增加,到100%時停止
ThreadmThread=newThread(newRunnable(){
publicvoidrun(){
for(inti=0;i<20;i++){
try{

iCount=(i+1)*5;
Thread.sleep(1000);

if(i==19){
Messagemsg=newMessage();
msg.what=STOP;
mHandler.sendMessage(msg);
break;
}else{
Messagemsg=newMessage();
msg.what=NEXT;
mHandler.sendMessage(msg);
}

}catch(Exceptione){
e.printStackTrace
}
}
}
});

//定義一個Handler
privateHandlermHandler=newHandler(){
publicvoidhandleMessage(Messagemsg){
switch(msg.what){
caseSTOP:
rectangleProgressBar.setVisibility(View.GONE);
circleProgressBar.setVisibility(View.GONE);
Thread.currentThread().interrupt();
break;

caseNEXT:
if(!Thread.currentThread().isInterrupted()){
rectangleProgressBar.setProgress(iCount);
circleProgressBar.setProgress(iCount);
}
}
}
}

⑸ 如何改變Android Progressbar默認顏色

默認情況下Indeterminate Progressbar是白色的,如果容器的背景也是白色的,這樣就根本看不到Progressbar了。

幸好Android自帶了一些反轉樣式,你可以採用其中一個合適的:

[Copy to clipboard]View Code XML

<ProgressBar style="@android:style/Widget.ProgressBar.Inverse"/>
<ProgressBar style="@android:style/Widget.ProgressBar.Large.Inverse"/>
<ProgressBar style="@android:style/Widget.ProgressBar.Small.Inverse"/>

⑹ android中ProgressBar載入完成後怎麼隱藏

用setVisible(View.GONE)方法就可以隱藏。

⑺ android progressbar的白色背景怎麼去掉

下面這個圖片是progressbar的各種樣式,不知道能不能滿足您的要求,例子來自於android學習手冊,360手機助手中可以下載,裡面有108個android例子,點擊源碼可以看源碼,點擊文檔可以看文檔。



1、說明

在某些操作的進度中的可視指示器,為用戶呈現操作的進度,還它有一個次要的進度條,用來顯示中間進度,如在流媒體播放的緩沖區的進度。一個進度條也可不確定其進度。在不確定模式下,進度條顯示循環動畫。這種模式常用於應用程序使用任務的長度是未知的。

2、XML重要屬性

android:progressBarStyle:默認進度條樣式

android:progressBarStyleHorizontal:水平樣式

3 重要方法

getMax():返回這個進度條的范圍的上限

getProgress():返回進度

getSecondaryProgress():返回次要進度

incrementProgressBy(int diff):指定增加的進度

isIndeterminate():指示進度條是否在不確定模式下

setIndeterminate(boolean indeterminate):設置不確定模式下

setVisibility(int v):設置該進度條是否可視

4 重要事件

onSizeChanged(int w, int h, int oldw, int oldh):當進度值改變時引發此事件

5進度條的樣式

Widget.ProgressBar.Horizontal長形進度

Androidxml 布局:

<ProgressBar

android:id="@+id/progress_bar"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

style="@android:style/Widget.ProgressBar.Horizontal "

/>

源碼:

private ProgressBar mProgress;

private int mProgressStatus=0;

private Handler mHandler=newHandler();

@Override

protected void onCreate(BundlesavedInstanceState){

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

mProgress=(ProgressBar)findViewById(R.id.progress_bar);

new Thread(new Runnable(){

@Override

public void run(){

while(mProgressStatus<100){

mProgressStatus=doWork();

mHandler.post(new Runnable(){

@Override

public void run(){

mProgress.setProgress(mProgressStatus);

}

});

}

}

}).start();

}

效果圖:

帶第二進度的進度條

xml配置如下:

<ProgressBar

android:id="@+id/progress_bar_with_second"

style="@android:style/Widget.ProgressBar.Horizontal"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:progress="40"

android:secondaryProgress="70"

android:paddingTop="20dp"

android:paddingBottom="20dp"/>

這里我們設置了初始的進度為40,android:progress的值在mini和max之間即mini<=progressvalue<=max

設置了第二進度條的進度值為70,該值也在mini和max之間。

效果如下:

不確定模式進度條

xml配置文件:

<ProgressBar

android:id="@+id/progress_bar_indeterminate"

style="@android:style/Widget.ProgressBar.Horizontal"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:indeterminate="true"

android:indeterminateBehavior="cycle"

android:paddingBottom="20dp"

android:paddingTop="20dp"

android:progress="40" />

這里通過android:indeterminate="true"設置了當前為無模式進度條

效果如圖:

普通圓形進度:Widget.ProgressBar.Inverse

<ProgressBar

android:id="@+id/progress_bar1"

style="@android:style/Widget.ProgressBar.Inverse"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:progress="50"

android:background="#ff00ff"

android:paddingTop="4dp" />

通過android:backgroup設置了背景色

⑻ android的Progressbar怎麼用

在android中,Progressbar可以用來提醒用戶某個任務的進度。下面我們來模擬一個下載進度來看一下。
首先我們創建一個按鈕來啟動一個帶有progressbar的提醒。

編寫代碼為按鈕添加一個點擊事件。

運行效果。

修改progressbar的風格。

完整的代碼。
public void onClick(View v) {

// prepare for a progress bar dialog
progressBar = new ProgressDialog(v.getContext());
progressBar.setCancelable(true);
progressBar.setMessage("File downloading ...");
progressBar.setProgressStyle(ProgressDialog.STYLE_SPINNER);
progressBar.setProgress(0);
progressBar.setMax(100);
progressBar.show();

//reset progress bar status
progressBarStatus = 0;

//reset filesize
fileSize = 0;

new Thread(new Runnable() {
public void run() {
while (progressBarStatus < 100) {

// process some tasks
progressBarStatus = doSomeTasks();

// your computer is too fast, sleep 1 second
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}

// Update the progress bar
progressBarHandler.post(new Runnable() {
public void run() {
progressBar.setProgress(progressBarStatus);
}
});
}

// ok, file is downloaded,
if (progressBarStatus >= 100) {

// sleep 2 seconds, so that you can see the 100%
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}

// close the progress bar dialog
progressBar.dismiss();
}
}
}).start();

}

});

}

// file download simulator... a really simple
public int doSomeTasks() {

while (fileSize <= 1000000) {

fileSize++;

if (fileSize == 100000) {
return 10;
} else if (fileSize == 200000) {
return 20;
} else if (fileSize == 300000) {
return 30;
}
// ...add your own

}

return 100;

}

⑼ android的Progressbar怎麼用

在Android中系統提供了多種Progressbar供開發者使用,開發者可以根據下面這個方法使用Progressbar控制項(系統是windows7,開發工具為Android studio)。

1、首先使用Android studio打開一個項目,如下圖:

熱點內容
sublimepython環境配置 發布:2025-05-20 02:36:13 瀏覽:577
cntv文件夾 發布:2025-05-20 02:33:20 瀏覽:219
vs設置編譯提示 發布:2025-05-20 02:33:10 瀏覽:216
android服務是什麼 發布:2025-05-20 02:19:31 瀏覽:201
什麼手機可以升到安卓十 發布:2025-05-20 02:19:24 瀏覽:570
手機U盤安卓的系統目錄里有什麼 發布:2025-05-20 02:13:08 瀏覽:849
python多進程鎖 發布:2025-05-20 02:12:23 瀏覽:293
n皇後演算法 發布:2025-05-20 01:49:15 瀏覽:66
如何配置圖形電腦 發布:2025-05-20 01:47:51 瀏覽:393
及解壓 發布:2025-05-20 01:44:49 瀏覽:416