如何更改进度条填充颜色而不是默认的绿色



我想根据进度条的百分比更改颜色。这是我的代码:

xml

<org.package.VerticalProgressBar
    android:id="@+id/Temp"
    style="@android:style/Widget.ProgressBar.Horizontal"
    android:layout_width="30dp"
    android:layout_height="120dp"
    android:layout_gravity="left"
    android:layout_marginBottom="5dip"
    android:layout_marginLeft="51dip"
    android:maxWidth="100dp"
    android:minWidth="0dp"/>

这就是我在我的应用程序中使用它的方式:

private static VerticalProgressBar progressBar;
progressBar=(VerticalProgressBar) findViewById(R.id.Temp);
progressBar.setProgress(12);

我应该在这里添加什么来设置进度条的颜色?

你能在android 中查看这个教程自定义进度条吗

//custom_progressbar.xml

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Define the background properties like color etc -->
    <item android:id="@android:id/background">
        <shape>
            <gradient
                    android:startColor="#000001"
                    android:centerColor="#0b131e"
                    android:centerY="1.0"
                    android:endColor="#0d1522"
                    android:angle="270"
            />
        </shape>
    </item>
 <!-- Define the progress properties like start color, end color etc -->
    <item android:id="@android:id/progress">
        <clip>
            <shape>
                <gradient
                    android:startColor="#007A00"
                    android:centerColor="#007A00"
                    android:centerY="1.0"
                    android:endColor="#06101d"
                    android:angle="270"
                />
            </shape>
        </clip>
    </item>
</layer-list>

并从中分配您的java代码-

// Get the Drawable custom_progressbar                     
Drawable customDrawable= res.getDrawable(R.drawable.custom_progressbar);
// set the drawable as progress drawavle
progressBar.setProgressDrawable(customDrawable);

最新更新