自定义进度条颜色

时间:2015-06-06 19:47:49

标签: android progress-bar

我正在尝试将默认 - 绿色进度条更改为紫色进度条。这里的一些人建议创建一个包含此代码的自定义drawable(progress.xml):

<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
    android:pivotX="50%" android:pivotY="50%" android:fromDegrees="0"
    android:toDegrees="360">
<shape android:shape="ring" android:innerRadiusRatio="3"
       android:thicknessRatio="8" android:useLevel="false">

    <size android:width="76dip" android:height="76dip" />
    <gradient android:type="sweep" android:useLevel="false"
              android:startColor="#61408c"
              android:endColor="#e1d2f3"
              android:angle="0"
        />
</shape>

并将其设置为进度条的背景属性,如下所示:

<ProgressBar
    style="?android:attr/progressBarStyleLarge"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/progressBar"
    android:background="@drawable/progress"
    android:layout_centerInParent="true"/>

问题在于我看到紫色和绿色进度条指示器。绿色位于紫色之上。我不知道绿色进度条来自哪里?效果是这样的: enter image description here

1 个答案:

答案 0 :(得分:0)

我想出来了。我应该在代码中设置它,而不是作为背景属性! 像这样:

mProgressBar = (ProgressBar) findViewById(R.id.progressBar);
    mProgressBar.setVisibility(View.INVISIBLE);
    mProgressBar.setIndeterminateDrawable(getDrawable(R.drawable.progress));
相关问题