Search code examples
androidandroid-layoutlayer-list

Create Custom circular progressbar with two layer


I want to create circular progress bar with two color

please Check image for Circular Progress Bar

enter image description here


Solution

  • Create custom drawable xml file and set this drawbale to your progressbar

    Check below answer

    <item>
        <rotate
            android:fromDegrees="0"
            android:pivotX="50%"
            android:pivotY="50%"
            android:repeatCount="infinite"
            android:toDegrees="1080">
            <shape
                android:innerRadiusRatio="3"
                android:shape="ring"
                android:thicknessRatio="12"
                android:useLevel="false">
    
                <size
                    android:width="76dip"
                    android:height="76dip"/>
                <gradient
                    android:angle="0"
                    android:endColor="@color/colorPrimary"
                    android:startColor="@color/colorPrimary"
                    android:type="linear"
                    android:useLevel="false"
                    />
            </shape>
        </rotate>
    </item>
    <item>
        <rotate
            android:fromDegrees="0"
            android:pivotX="50%"
            android:pivotY="50%"
            android:repeatCount="infinite"
            android:toDegrees="1080">
            <shape
                android:innerRadiusRatio="3"
                android:shape="ring"
                android:thicknessRatio="22"
                android:useLevel="false">
    
                <size
                    android:width="76dip"
                    android:height="76dip"/>
                <gradient
                    android:angle="0"
                    android:endColor="@android:color/white"
                    android:startColor="@android:color/transparent"
                    android:type="sweep"
                    android:useLevel="false"
                    />
            </shape>
        </rotate>
    </item>
    

    set this drawable to your progress bar

     <ProgressBar
                android:id="@+id/loadingbar"
                style="?android:attr/progressBarStyle"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/img"
                android:layout_centerInParent="true"
                android:indeterminateDrawable="@drawable/custom_progress_bar" />
    

    Hope this will help you

    Put your second color instead of @color/colorPrimary