Rounded progress within Rounded progressbar
<ProgressBar
android:id="@+id/progress"
style="@android:style/Widget.ProgressBar.Horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:indeterminate="false"
android:progress="100"
android:progressDrawable="@drawable/progress" />
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/background">
<shape>
<corners android:radius="20dp" />
<solid android:color="@android:color/transparent" />
<stroke android:color="@color/black_20" android:width="0.5dp" />
</shape>
</item>
<item android:id="@android:id/progress">
<scale android:drawable="@drawable/custom_progress_primary"
android:scaleWidth="90%"/>
</item>
</layer-list>
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners
android:radius="20dp"
android:topLeftRadius="20dp"
android:topRightRadius="20dp" />
<solid android:color="@color/progress_one" />
</shape>
在代码中改变进度条的颜色
一般思路是设置了该xml文件后,直接通过
但是这样设置无效,需要将xml中的各层都取出来,然后改变前景色
LayerDrawable ld = (LayerDrawable) mContext.getResources()
.getDrawable(R.drawable.vote_progress_bar_voting);
GradientDrawable gd = (GradientDrawable)ld.
findDrawableByLayerId(android.R.id.background);
ScaleDrawable fd = (ScaleDrawable)ld.
findDrawableByLayerId(android.R.id.progress);
fd.setColorFilter(redContent, PorterDuff.Mode.SRC_OVER);
progressBar.setProgressDrawable(ld);