2016-04-15 11 views
1

円の進行状況バーのデフォルト色を変更する方法がわかりません。私は、下のxmlファイルのタイトルcircular_progress_view.xmlの緑の色ですが、マゼンタのデフォルトの色がまだ表示されている私の勾配タグの下でstartColorとendcolorの属性を変更しようとしました。私はこれと作品のようにそれを行う私のレイアウトxmlファイル(main.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

以下circular_progress_view.xmlファイルの両方を参照してください。かなり細かい

<?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" />