更改进度条颜色
Changing the progress bar color
我在我的 Activty 中使用了一个圆形 ProgressBar。
我的问题是它的颜色没有正确改变,只有 BG 颜色在改变。
那么如何在没有BG的情况下更改ProgressBar的颜色。
我试过这个线程- How to change default color of progress bar?
http://i.stack.imgur.com/DEpyM.jpg
您可以在 xml 个文件中完成所有操作
经过一番搜索,我得到了答案:
你进度条码:
<ProgressBar
android:id="@+id/progressBar"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:max="100"
android:indeterminateDrawable="@drawable/progress"
/>
进度可绘制对象由一个旋转环组成,具有您选择的渐变颜色,如下所示:
<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:pivotX="50%" android:pivotY="50%" android:fromDegrees="0"
android:toDegrees="360">
<shape android:shape="ring" android:innerRadiusRatio="3"
android:thicknessRatio="8" android:useLevel="false">
<size android:width="76dip" android:height="76dip" />
<gradient android:type="sweep" android:useLevel="false"
android:startColor="#007700"
android:endColor="#115511"
android:angle="0"
/>
</shape>
</rotate>
就像这样,请评价这个答案:)
更好的方法(使用 AppCompat 库):
final int color = Color.WHITE; // Or any other one
final ProgressBar progressBar= (ProgressBar) findViewById(R.id.progress_bar);
DrawableCompat.setTint(progressBar.getIndeterminateDrawable(), color);
我在我的 Activty 中使用了一个圆形 ProgressBar。 我的问题是它的颜色没有正确改变,只有 BG 颜色在改变。 那么如何在没有BG的情况下更改ProgressBar的颜色。 我试过这个线程- How to change default color of progress bar?
http://i.stack.imgur.com/DEpyM.jpg
您可以在 xml 个文件中完成所有操作 经过一番搜索,我得到了答案:
你进度条码:
<ProgressBar
android:id="@+id/progressBar"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:max="100"
android:indeterminateDrawable="@drawable/progress"
/>
进度可绘制对象由一个旋转环组成,具有您选择的渐变颜色,如下所示:
<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:pivotX="50%" android:pivotY="50%" android:fromDegrees="0"
android:toDegrees="360">
<shape android:shape="ring" android:innerRadiusRatio="3"
android:thicknessRatio="8" android:useLevel="false">
<size android:width="76dip" android:height="76dip" />
<gradient android:type="sweep" android:useLevel="false"
android:startColor="#007700"
android:endColor="#115511"
android:angle="0"
/>
</shape>
</rotate>
就像这样,请评价这个答案:)
更好的方法(使用 AppCompat 库):
final int color = Color.WHITE; // Or any other one
final ProgressBar progressBar= (ProgressBar) findViewById(R.id.progress_bar);
DrawableCompat.setTint(progressBar.getIndeterminateDrawable(), color);