2016-11-01 62 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

它不工作 –