Android custom empty cicrle progress bar color issue

时间:2017-08-13 14:07:57

标签: android progress-bar android-custom-view

I have custom circle progressbar in Android which I made with drawable circular.xml

Here is my progressbar:

<ProgressBar
    android:id="@+id/circle_progress_id"
    style="?android:attr/progressBarStyleHorizontal"
    android:layout_width="40dp"
    android:layout_height="40dp"
    android:indeterminate="false"
    android:max="100"
    android:rotation="-90"
    android:progressDrawable="@drawable/circular"
    android:layout_toRightOf="@id/checkbox_id"
    android:background="@drawable/circle_shape"/>

Here is code from @drawable/circular

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape
            android:innerRadiusRatio="3.4"
            android:shape="ring"
            android:thicknessRatio="9.0"
            android:useLevel="true" >
            <gradient
                android:endColor="#4CAF50"
                android:startColor="#4CAF50"
                android:type="sweep"
                android:useLevel="true" />
        </shape>
    </item>
</selector>

And it works fine and show progress after:

recyclerTaskHolder.progressBarStage.setProgress(getStageProgressValue(myTask));

But it absolutely empty when it is zero progress. I need to show for user empty gray color progress bar when it is zero progress. Or show empty part of progress bar with gray color when it is between zero and 100%.

I tried to make custom background of progress bar

android:background="@drawable/circle_shape"

Here is circle_shape.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape
            android:innerRadiusRatio="3.4"
            android:shape="ring"
            android:thicknessRatio="9.0"
            android:useLevel="true"
            android:visible="true">
            <gradient
                android:endColor="#000000"
                android:startColor="#000000"
                android:type="sweep"
                android:useLevel="true" />
        </shape>
    </item>
</selector>

But it didn't help me and empty progress bar is still invisible.

1 个答案:

答案 0 :(得分:0)

不幸的是我没有找到这个问题的原因。 但是我将这个库用于Circle Progress Bar并且工作正常。 CircularProgressBar

这个库很容易使用。