Android Progress 设置进度的背景色

<ProgressBar
            android:id="@+id/progressBar_one"
            android:layout_marginLeft="30dp"
            android:layout_marginRight="30dp"
            android:layout_width="match_parent"
            android:layout_height="30dp"
            style="?android:attr/progressBarStyleHorizontal"
            android:progressDrawable="@drawable/progressbar_style"
            android:max="100"
            android:layout_marginTop="20dp"
            />

最近项目中要求做一个横向的柱状图,没找到好的例子,就用ListView + progress  代替了,每个条目里面放置一个

代码里设置progressbar的背景色:


mProgressBar = (ProgressBar) findViewById(R.id.progressBar_one);
        Drawable progressDrawable=getResources().getDrawable(R.drawable.<span style="font-family: Arial, Helvetica, sans-serif;">progressbar_style</span>);
        mProgressBar.setProgressDrawable(progressDrawable);
        mProgressBar.setProgress(70);


progressbar_style 
<?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="6.0dip" /> <!--圆角-->
    <gradient android:startColor="#f7f7f7"
              android:endColor="#f7f7f7"
              android:angle="270.0"
              android:centerY="0.75"
              android:centerColor="#f7f7f7" /> <!--渐变的背景-->
    <stroke android:width="0.5dp" android:color="#7d7f83" /><!-- 描边,边框宽度、颜色 -->

</shape>
</item>

    <!--第二条进度,可以不需要-->
<item android:id="@android:id/secondaryProgress">
<clip>
    <shape>
        <corners  android:radius="6.0dip" />
        <gradient android:startColor="#e71a5e"
                  android:endColor="#6c213a"
                  android:angle="90.0"
                  android:centerY="0.75"
                  android:centerColor="#ac6079" />
        <stroke android:width="0.5dp" android:color="#7d7f83" />
    </shape>
</clip>
</item>

    <!--进度颜色-->
<item android:id="@android:id/progress">
<clip>
    <shape>
        <corners android:radius="6.0dip" />
        <gradient
                android:startColor="#e2e4e8"
                android:endColor="#e2e4e8"
                android:centerColor="#e2e4e8"
                android:angle="270.0" />
        <stroke android:width="0.5dp" android:color="#7d7f83" />
    </shape>
</clip>
</item>
</layer-list>


 


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值