Android:使用自定义颜色的默认不确定进度条的XML

4

我需要制作一个不定进度条,它与默认小部件完全相同,只是颜色不同。由于我需要支持 api 15+,所以无法使用着色。

迄今为止,我的解决方案是使用自定义的 drawable 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="360">

    <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="somecolor" android:centerColor="somecolor"
            android:centerY="0.50" android:endColor="somecolor" />

    </shape>

</rotate> 

然后这样定义自定义的drawable:

        <ProgressBar
        android:id="@+id/customprogressbar"
        android:layout_width="42dp"
        android:layout_height="35dp"
        android:layout_gravity="center"
        android:visibility="gone"
        android:indeterminateDrawable="@drawable/customprogressbardrawable"
        style="@android:style/Widget.ProgressBar"
        />

这有效,但它看起来不像默认的进度条。我可以使用哪些默认设置,或者有没有更好的方法使我的进度条在所有方面都与默认小部件相同,只是颜色不同?

1
这可能会帮助您:https://dev59.com/3F8d5IYBdhLWcg3wch2i - Rahul Tiwari
不是重复问题...谁标记为重复肯定没有看到“因为我需要支持API 15+”这部分。 - Jake
1个回答

3

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接