如何设置颜色以进度条二级绘 [英] How to set color to secondary drawable in progress bar

查看:140
本文介绍了如何设置颜色以进度条二级绘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的code

 pb = (ProgressBar) findViewById(R.id.progressBar1);
    final float[] roundedCorners = new float[] { 5, 5, 5, 5, 5, 5, 5, 5 };
    ShapeDrawable pgDrawable = new ShapeDrawable(new RoundRectShape(roundedCorners, null, null));
    String MyColor = "#00FF00";
    pgDrawable.getPaint().setColor(Color.parseColor(MyColor));
    ClipDrawable progress = new ClipDrawable(pgDrawable, Gravity.LEFT, ClipDrawable.HORIZONTAL);
    pb.setProgressDrawable(progress);
    pb.setBackgroundDrawable(getResources().getDrawable(android.R.drawable.progress_horizontal));

在此code的问题是,对于进度绘制和二级进度绘我也有同样的颜色。

The problem in this code is that for the progress drawable and for the secondary progress drawable I have the same color.

如何设置socondary进度颜色?

How to set the socondary progress color ?

推荐答案

指定 progressDrawable 就像下面的例子:

这都到了布局:

<ProgressBar
    android:id="@+id/gauge"
    style="?android:attr/progressBarStyleHorizontal"
    android:layout_width="wrap_content"
    android:layout_height="4dp"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:layout_below="@+id/section"
    android:progress="50" 
    android:progressDrawable="@drawable/progressbar"/>

这正好绘制/ progressbar.xml ,在这里你可以指定背景和颜色两个进度条。

This goes to drawable/progressbar.xml, and here you can specify background and colors for both progress bars.

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

<item android:id="@android:id/background">
    <shape>
        <gradient
                android:startColor="@color/basecolor"
                android:endColor="@color/basecolor"
                android:angle="270"
        />
    </shape>
</item>

<item android:id="@android:id/secondaryProgress">
    <clip>
        <shape>
            <gradient
                    android:startColor="#808080"
                    android:endColor="#808080"
                    android:angle="270"
            />
        </shape>
    </clip>
</item>
<item android:id="@android:id/progress">
    <clip>
        <shape>
            <gradient
                android:startColor="#ffcc33"
                android:endColor="#ffcc33"
                android:angle="270" />
        </shape>
    </clip>
</item>

这篇关于如何设置颜色以进度条二级绘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆