我正在尋找一個非常明顯的事情(用其他語言!!),它讓我瘋狂!如何更改android不確定的ProgressBar顏色?
我想知道如何將不確定的ProgressBar顏色從基礎白色/灰色更改爲黑色?當我改變indeterminateDrawable,我得到一個靜態圖像,而不是一個移動的動畫progressBar。有什麼辦法可以簡單地在xml中完成嗎?
謝謝!
我正在尋找一個非常明顯的事情(用其他語言!!),它讓我瘋狂!如何更改android不確定的ProgressBar顏色?
我想知道如何將不確定的ProgressBar顏色從基礎白色/灰色更改爲黑色?當我改變indeterminateDrawable,我得到一個靜態圖像,而不是一個移動的動畫progressBar。有什麼辦法可以簡單地在xml中完成嗎?
謝謝!
實際上所有你需要做的(對於cirle和bar)是創建一個可繪製的xml文件,如下所示...... progress_spinner_001指向任何你想要動畫和持續時間的圖像......多長時間ü要顯示的每個幀爲....... 並設置烏爾機器人:indeterminateDrawable = filename_in_drawable ....
<?xml version="1.0" encoding="utf-8"?>
<animation-list
xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false">
<item android:drawable="@drawable/progress_spinner_001" android:duration="300" />
<item android:drawable="@drawable/progress_spinner_002" android:duration="300" />
<item android:drawable="@drawable/progress_spinner_003" android:duration="300" />
<item android:drawable="@drawable/progress_spinner_004" android:duration="300" />
<item android:drawable="@drawable/progress_spinner_005" android:duration="300" />
<item android:drawable="@drawable/progress_spinner_006" android:duration="300" />
<item android:drawable="@drawable/progress_spinner_007" android:duration="300" />
<item android:drawable="@drawable/progress_spinner_008" android:duration="300" />
</animation-list>
Ps作爲期望
U可需要調整進度條顯示要在默認主題中使用白色/淺色背景中的ProgressBar,請使用其中一種逆向樣式:
<ProgressBar style="@android:style/Widget.ProgressBar.Inverse"/>
<ProgressBar style="@android:style/Widget.ProgressBar.Large.Inverse"/>
<ProgressBar style="@android:style/Widget.ProgressBar.Small.Inverse"/>
這通常會讓您在透明的ProgressBar上顯示黑色,但某些操作系統安裝使用自定義資源。如果您正在尋找特定的顏色,您必須按照CommonsWare提供的說明滾動自己的繪圖。
我製作示例項目並在我的博客中發佈。請看,看看。 http://www.hrupin.com/2011/09/21/how-to-make-custom-indeterminate-progressbar-in-android-or-how-to-change-progressbar-style-or-color
希望,它幫助你
你搖滾,哥們;)隨時可用的代碼,幫我噸 – myro 2012-04-18 10:16:35
<?xml version="1.0" encoding="UTF-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/background" android:drawable="@drawable/bg" />
<item android:id="@android:id/secondaryProgress" android:drawable="@drawable/secondary" />
<item android:id="@android:id/progress" android:drawable="@drawable/progress" />
</layer-list>
progressBar.getIndeterminateDrawable().setColorFilter(
getResources().getColor(Your_Color),
android.graphics.PorterDuff.Mode.SRC_IN);
,並與像期望的顏色替換Your_Color:R.color.your_color_code
這應該是可以接受的答案;) – Leo 2015-06-02 01:54:34
這是最快捷最簡單的方法。 – 2015-12-16 14:00:19
可以在xml中定義:'android:indeterminateTint =「@ colors/your_color」''android:indeterminateTintMode =「src_in」' – zhaoyuanjie 2016-01-05 10:45:09
我看到其他的答案是很老,爲了改變不確定的ProgressBar顏色,您只需在您的ProgressBar
項目中直接以XML格式設置android:indeterminateTint
和android:indeterminateTintMode
屬性:
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:indeterminateTint="@color/colorPrimary"
android:indeterminateTintMode="src_in"
android:indeterminate="true" />
android:indeterminateTint
- 適用於不確定進度指標的色調。
必須是顏色值,在
"#rgb"
,"#argb"
,"#rrggbb"
,"#aarrggbb"
的形式,或者以一個資源@color/colorPrimary
的參考。
android:indeterminateTintMode
- 用於應用進度指示符色調的混合模式。
必須是以下恆定值之一:
add
,multiply
,screen
,src_atop
,src_in
或src_over
Getter和這些屬性設置器方法是:
getIndeterminateTintList()
getIndeterminateTintMode()
setIndeterminateTintList(ColorStateList tint)
setIndeterminateTintMode(PorterDuff.Mode tintMode)
他們都在API level 21
加入對於API小於23使用
progressBar.getIndeterminateDrawable().setColorFilter(
getResources().getColor(Your_Color),
android.graphics.PorterDuff.Mode.SRC_IN);
使用別的
progressBar.getIndeterminateDrawable().setColorFilter(
ContextCompat.getColor(context, Your_Color),
android.graphics.PorterDuff.Mode.SRC_IN);
-1:這個答案說「如下所示」,但它什麼也沒有顯示。我覺得很難理解。 – 2012-02-16 14:53:42