【发布时间】:2019-02-16 12:19:48
【问题描述】:
这是我自定义的白色透明滚轮 ProgressBar
progressbar_circle.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="4dp"
android:useLevel="false">
<gradient
android:type="sweep"
android:startColor="@android:color/white"
android:centerColor="@android:color/white"
android:endColor="@android:color/transparent"
/>
</shape>
在 Android Studio 的预览窗口中,该元素已正确显示。
但在模拟器 (Android 9) 和设备 (Android 6) 中进行调试测试后,ProgressBar 显示为@color/colorAccent wheel Progressbar。
我尝试过更改 android:shape、android:innerRadiusRatio、android:thickness,甚至将渐变更改为纯色。没有任何改变。
这是我的 progress_task_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:id="@+id/correct_icon"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:contentDescription="@string/correct_icon"
android:padding="@dimen/padding_large"
android:visibility="gone" />
<ProgressBar
android:id="@+id/progress_bar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="8dp"
android:padding="@dimen/padding_large"
android:progressDrawable="@drawable/progressbar_circle"
android:visibility="gone" />
</RelativeLayout>
如何在 xml 上实现自定义 android ProgressBar 而无需在 java 中动态编程?
【问题讨论】:
-
如果你的 min api > = 21 你可以使用
android:indeterminateTint="@android:color/white" -
@NongthonbamTonthoi 我设置 min api = 14
android:indeterminateTint="@android:color/white"用于纯色,渐变色怎么样。 (我稍后会处理旧的 api 版本。)
标签: android android-xml android-progressbar