How to set a progress indicator

I set the progressbar style using the code below.

I declared a progressbar widget:

 <ProgressBar
    android:id="@+id/loadProgress"
    style="?android:attr/progressBarStyleHorizontal"
    android:layout_width="match_parent"
    android:layout_height="20dip"
    android:max="100"
    android:progressDrawable="@drawable/load_progress"
    android:progress="0" />

defined "@ drawable / load_progress"

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

<item
    android:id="@android:id/background"
    android:drawable="@drawable/background_bk">
</item>
<item
    android:id="@android:id/progress"
    android:drawable="@drawable/progress_bk">
</item>

</layer-list>

defined "@ drawable / background_bk" (red)

<?xml version="1.0" encoding="utf-8"?>
 <shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >

<gradient
    android:angle="0"
    android:endColor="#ff0000"
    android:startColor="#ff0990" />

<stroke
    android:width="1dp"
    android:color="#ff0000" />

 </shape>

@ drawable / progress_bk set (it is green)

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >

<gradient
    android:angle="0"
    android:endColor="#00ff00"
    android:startColor="#00ff00" />

<stroke
    android:width="1dp"
    android:color="#00ff00" />

</shape>

The progress indicator is always displayed completely green (how it should look when the progress value is 100), even if I set the progress value to less than 100. Any input would be appreciated.

+4
source share
2 answers

Finally, I find an easy solution.

1

you can find the default xml file that you want to delete in the folder "SDK_path \ platform \ android19 \ Data \ res \ draw" At the top you can find a lot of default style for many widgets.

2

"progress_horizontal.xml". :

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

<item android:id="@android:id/background">
    <shape>
        <corners android:radius="5dip" />
        <gradient
                android:startColor="#ff9d9e9d"
                android:centerColor="#ff5a5d5a"
                android:centerY="0.75"
                android:endColor="#ff747674"
                android:angle="270"
        />
    </shape>
</item>

<item android:id="@android:id/secondaryProgress">
    <clip>
        <shape>
            <corners android:radius="5dip" />
            <gradient
                    android:startColor="#80ffd300"
                    android:centerColor="#80ffb600"
                    android:centerY="0.75"
                    android:endColor="#a0ffcb00"
                    android:angle="270"
            />
        </shape>
    </clip>
</item>

<item android:id="@android:id/progress">
    <clip>
        <shape>
            <corners android:radius="5dip" />
            <gradient
                    android:startColor="#ffffd300"
                    android:centerColor="#ffffb600"
                    android:centerY="0.75"
                    android:endColor="#ffffcb00"
                    android:angle="270"
            />
        </shape>
    </clip>
</item>

</layer-list>

3

" " " ".

+2

, :

android:background="@color/white"
android:progressBackgroundTint="@color/white"
android:progressTint="@color/green_light"
0

All Articles