2016-11-01 61 views

回答

0

您可以使用自定義drawable。用您的顏色替換colorAccent和其他顏色。

<?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="1440" > 

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

     <size 
      android:height="75dip" 
      android:width="75dip" /> 

     <gradient 
      android:angle="0" 
      android:endColor="@color/colorAccent" 
      android:centerColor="@color/colorAccentCenter" 
      android:startColor="@color/colorAccentCenter" 
      android:type="sweep" 
      android:useLevel="false" /> 

    </shape> 

</rotate> 
+0

嗨,上面的代碼工作與我,但無論如何要通過Java代碼做到這一點? – Glenn

+0

讓我看看。 我建議你按照這個例子,截至目前。 http://stackoverflow.com/questions/10951978/change-progressbar-color-through-code-only-in-android – vidulaJ

+0

該解決方案使用了'ProgressBar'不'ProgressDialog' – Glenn

0

你可以寫在style.xml風格V21文件夾下象下面這樣:

<style name="ProgressBar" parent="Base.Widget.AppCompat.ProgressBar"> <item name="android:colorAccent">@color/red</item> </style>

,並使用它像這樣

ProgressDialog myProgressDialog = new ProgressDialog(MyActivity.this); myProgressDialog.setProgressStyle(R.style.ProgressBar) myProgressDialog.show();

+0

以上v21怎麼樣? – Glenn

+0

當你把它放在v21文件夾中時,它也支持上面的API。 –

+2

它不工作 –