2016-04-15 78 views
1

我无法弄清楚如何更改我的圆形进度栏的默认颜色。我尝试在下面的XML文件标题circular_progress_view.xml中更改我的渐变标记下的startColor和endcolor属性,这是一个荧光绿色,但洋红色的默认颜色仍显示出来。请参阅我的两个布局的XML文件(main.xml中)和circular_progress_view.xml文件下Android:如何更改圆形进度条上的自定义颜色

main.xml中

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    android:descendantFocusability="blocksDescendants"> 

    <LinearLayout 
     android:id="@+id/linlaHeaderProgress" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:gravity="center" 
     android:orientation="vertical" 
     android:visibility="gone" > 

     <ProgressBar 
      android:indeterminate="true" 
      style="?android:attr/progressBarStyleLarge" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:id="@+id/progressBar" 
      android:progressDrawable="@drawable/circular_progress_view"> 
     </ProgressBar> 
    </LinearLayout> 

    <ListView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:id="@+id/listview" 
     android:layout_weight="1"> 

    </ListView> 


    <Button 
     android:id="@+id/btn" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:text="Submit"/> 


</LinearLayout> 

circular_progress_view.xml

<?xml version="1.0" encoding="utf-8"?> 
<rotate xmlns:android="http://schemas.android.com/apk/res/android" 

    android:fromDegrees="90" 
    android:pivotX="50%" 
    android:pivotY="50%" 
    android:toDegrees="360"> 

    <shape 
     android:innerRadiusRatio="3" 
     android:shape="ring" 
     android:thicknessRatio="7.0"> 

     <gradient 
      android:angle="0" 
      android:type="sweep" 
      android:useLevel="false" 
      android:startColor="#00FF00" 
      android:endColor="#00FF00"/> 

    </shape> 



</rotate> 

回答

1

我不喜欢这样的作品和很好

<?xml version="1.0" encoding="utf-8"?> 
<rotate xmlns:android="http://schemas.android.com/apk/res/android" 
    android:fromDegrees="0" 
    android:pivotX="50%" 
    android:pivotY="50%" 
    android:toDegrees="1080" > 

    <shape 
     android:innerRadiusRatio="3" 
     android:shape="ring" 
     android:thicknessRatio="12" 
     android:useLevel="false" > 

     <size 
      android:height="76dp" 
      android:width="76dp" /> 

     <gradient 
      android:angle="0" 
      android:endColor="@color/progress_bar_color" 
      android:startColor="@android:color/transparent" 
      android:type="sweep" 
      android:useLevel="false" /> 

    </shape> 
</rotate> 

并将此添加到res/values/colors.xml

<color name="progress_bar_color">#00ff00</color> 

我添加进度是这样的(注意安卓indeterminateDrawable):

<ProgressBar 
      android:id="@+id/progress_bar" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_margin="5dp" 
      android:indeterminate="true" 
      android:indeterminateDrawable="@drawable/progress_bar" 
      style="?android:attr/progressBarStyleLargeInverse" />