Custom indeterminate ProgressBar

自定义 Indeterminate ProgressBar:
先定义一个ring shape
custom_progress_bar.xml
<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="4000"
    android:fromDegrees="0"
    android:pivotX="50%"
    android:pivotY="50%"
    android:toDegrees="1440">

    <shape
        android:innerRadius="9dp"
        android:shape="ring"
        android:thickness="2dp"
        android:useLevel="false">
        <size
            android:width="22dp"
            android:height="22dp" />
        <gradient
            android:centerColor="#991994EC"
            android:centerY="0.5"
            android:endColor="#1DB2EE"
            android:startColor="#00ec7e2a"
            android:type="sweep"
            android:useLevel="false" />
    </shape>

</rotate>


直接在layout中使用
<ProgressBar
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:indeterminateDrawable="@drawable/custom_progress_bar"
                        android:minWidth="25dp" />


注意定义上面的android:minWidth,可以调整ProgressBar的Padding效果

5.0以上,自定义progressbar的颜色,可以简单使用:
android:indeterminateTintMode="src_atop"
android:indeterminateTint="@color/your_customized_color"

猜你喜欢

转载自enuocm.iteye.com/blog/2377824