1、在布局文件中有ProgressBar
<ProgressBar
android:id="@+id/pb_volume"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="1dp"
android:max="100"
android:progress="0"
android:visibility="visible" />
2、定义 layer-list, buy_progress.xml文件
<?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>
<gradient android:startColor="@color/colorGreenTrans"
android:endColor="@color/colorGreenTrans" />
</shape>
</item>
<item android:id="@android:id/progress" >
<clip>
<shape>
<gradient android:startColor="@color/colorDefault"
android:endColor="@color/colorDefault" />
</shape>
</clip>
</item>
</layer-list>
3、在代码设置方法如下
Drawable drawable = mContext.getResources().getDrawable(R.drawable.buy_progress)
pbVolume.setProgressDrawable(drawable);
4、最终效果如下:
注:标红部分是设置背影与进度的. 颜色自己定义