android ProgressBar 设置背影色与进度色

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、最终效果如下:


 

注:标红部分是设置背影与进度的. 颜色自己定义

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值