我在Android上使用圆形进度条,希望改变它的颜色。我正在使用
"?android:attr/progressBarStyleLargeInverse"
如何更改进度条的颜色?需要怎样自定义样式呢?此外,“style”在这里的定义是什么?
我在Android上使用圆形进度条,希望改变它的颜色。我正在使用
"?android:attr/progressBarStyleLargeInverse"
如何更改进度条的颜色?需要怎样自定义样式呢?此外,“style”在这里的定义是什么?
请查看这个答案:
对于我来说,为了让它起作用并改变颜色,这两行必须存在:
android:indeterminateTint="@color/yourColor"
android:indeterminateTintMode="src_in"
PS:但仅适用于 Android 21 及以上版本
对我来说,主题在使用accentColor时无法工作。但是它可以使用colorControlActivated。
<style name="Progressbar.White" parent="AppTheme">
<item name="colorControlActivated">@color/white</item>
</style>
<ProgressBar
android:layout_width="@dimen/d_40"
android:layout_height="@dimen/d_40"
android:indeterminate="true"
android:theme="@style/Progressbar.White"/>
<style name="progressColor" parent="Widget.AppCompat.ProgressBar">
<item name="colorControlActivated">@color/colorPrimary</item>
</style>
<ProgressBar
android:id="@+id/progressBar"
android:layout_width="250dp"
android:theme="@style/progressColor"
android:layout_height="250dp"
android:layout_centerInParent="true" />
补充Muhamed Riyas M的最受欢迎答案:
更快的旋转
android:toDegrees="1080"
android:thicknessRatio="16"
浅白色
android:endColor="#80ffffff"
将colorControlActivated主题项添加到您的活动主题中,例如:
<style name="AppTheme.NoActionBar" parent="Theme.AppCompat.Light.NoActionBar">
...
<item name="colorControlActivated">@color/rocket_black</item>
...
</style>
在清单文件中将此样式应用于您的Activity:
<activity
android:name=".packege.YourActivity"
android:theme="@style/AppTheme.NoActionBar"/>
尝试使用样式并将colorControlActivated设置为所需的ProgressBar颜色。
<style name="progressColor" parent="Widget.AppCompat.ProgressBar">
<item name="colorControlActivated">@color/COLOR</item>
</style>
接着将ProgressBar的主题设置为新样式。
<ProgressBar
android:id="@+id/progress_bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:theme="@style/progressColor"
/>
您可以使用以下样式来更改进度条的颜色:
<style name="AppTheme.anyName">
<item name="colorAccent">YOUR_COLOR</item>
</style>
<ProgressBar
style="?android:attr/progressBarStyle"
android:theme="@style/AppTheme.WhiteAccent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/dimen_30"
/>
<?xml version="1.0" encoding="utf-8"?>
<shape
android:innerRadiusRatio="3"
android:shape="ring"
android:thicknessRatio="8"
android:useLevel="false" >
<size
android:height="76dip"
android:width="76dip" />
<gradient
android:angle="0"
android:endColor="@color/oceanBlue"
android:startColor="@android:color/transparent"
android:type="sweep"
android:useLevel="false" />
</shape>
只需要这样做:
public static class ModifiedProgressDialog extends ProgressDialog {
public ModifiedProgressDialog(Context context) {
super(context);
}
@Override
public void show() {
super.show();
setIndeterminateDrawable(getContext().getResources().getDrawable(R.drawable.blue_progress));
}
}
<?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="1080"><!--HERE YOU COULD INCREASE SPEED BY SETTING TODEGRESS(1080 is 3 loops instead of 1 in same amt of time)-->
<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="#447a29"
android:endColor="#447a29"
android:angle="0"
/>
</shape>
将android:indeterminateDrawable="@drawable/progress_custom_rotate"
设置为:
使用以下代码自定义圆形进度条:
复制下面的代码并在Drawable文件夹中创建"progress_custom_rotate.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="1080">
<shape android:shape="ring" android:innerRadiusRatio="3"
android:thicknessRatio="8" android:useLevel="false">
<size android:width="48dip" android:height="48dip" />
<gradient android:type="sweep" android:useLevel="false"
android:startColor="#4c737373" android:centerColor="#4c737373"
android:centerY="0.50" android:endColor="#ffffd300" />
</shape>
</rotate>