Android 如何设置确定圆形进度条的二次颜色
我想更改确定进度条的主颜色和次颜色,分别为绿色和灰色。Android默认进度条甚至不显示辅助进度。我怎样才能做到这一点?谢谢Android 如何设置确定圆形进度条的二次颜色,android,android-layout,android-xml,android-progressbar,Android,Android Layout,Android Xml,Android Progressbar,我想更改确定进度条的主颜色和次颜色,分别为绿色和灰色。Android默认进度条甚至不显示辅助进度。我怎样才能做到这一点?谢谢 <ProgressBar android:id="@+id/progress_circular" android:layout_width="256dp" android:layout_height="256dp" android:indeterminate="false" style=
<ProgressBar
android:id="@+id/progress_circular"
android:layout_width="256dp"
android:layout_height="256dp"
android:indeterminate="false"
style="?android:attr/progressBarStyleLarge"
android:layout_marginTop="18dp"
app:layout_constraintTop_toBottomOf="@id/textView2"
app:layout_constraintStart_toStartOf="@id/mainView"
android:progress="50"
app:layout_constraintEnd_toEndOf="@id/mainView"
/>
您可以创建自定义progressbar样式 custom_progress.xml
和xml格式:
<ProgressBar
android:layout_centerInParent="true"
android:id="@+id/winRateProgressBar"
android:layout_width="48dp"
android:layout_height="48dp"
style="?android:attr/progressBarStyleHorizontal"
android:indeterminate="false"
android:max="100"
android:progress="20"
android:progressDrawable="@drawable/custom_progress"/>
要自定义进度条,请执行以下操作
在xml中
<ProgressBar
android:id="@+id/progress_circular"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="256dp"
android:layout_height="256dp"
android:layout_marginTop="18dp"
app:layout_constraintTop_toBottomOf="@id/textView2"
app:layout_constraintStart_toStartOf="@id/mainView"
android:progress="50"
app:layout_constraintEnd_toEndOf="@id/mainView"
android:background="@drawable/circle_shape"
android:indeterminate="false"
android:progressDrawable="@drawable/circular_progress_bar" />
和圆形进度条xml
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="ring"
android:innerRadiusRatio="2.5"
android:thickness="1dp"
android:useLevel="false">
<solid android:color="#CCC" /> // use your color here
</shape>
<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="270"
android:toDegrees="270">
<shape
android:innerRadiusRatio="2.5"
android:shape="ring"
android:thickness="2dp"
android:useLevel="true"><!-- this line fixes the issue for lollipop api 21 -->
<gradient
android:angle="0"
android:endColor="#ffffff"
android:startColor="#ffffff"
android:type="sweep"
android:useLevel="false" />
</shape>
</rotate>
将您的代码与问题一起发布。我已更新了可用于ProgressBar绘制的codeCreate自定义进度。@MushahidGillani请参考此答案@Prashant抱歉,它不起作用。我如何才能使进度的边缘圆整,如上图所示抱歉。我刚才看了你的问题。我在顶部编辑了我的答案)你们可以看看!
<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="270"
android:toDegrees="270">
<shape
android:innerRadiusRatio="2.5"
android:shape="ring"
android:thickness="2dp"
android:useLevel="true"><!-- this line fixes the issue for lollipop api 21 -->
<gradient
android:angle="0"
android:endColor="#ffffff"
android:startColor="#ffffff"
android:type="sweep"
android:useLevel="false" />
</shape>
</rotate>