2015-06-06 142 views
0

我正在尝试将默认 - 绿色进度栏更改为紫色。这里有些人建议包含此代码创建一个自定义绘制(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

回答

0

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

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