How to set progressbar background

I have set the progressbar style using the below code.

I have declared the 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 the "@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 the "@drawable/background_bk" (it is 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>

defined the @drawable/progress_bk (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 progressbar always shows totally green (which is how it should appear when the progress value is 100), even if I set the progress value to less than 100. Any input would be appreciated.


ANSWERS:


Finally, I find a easy solution.

1

you can find the default drawable xml file in your folder "SDK_path\platforms\android19\data\res\drawable" Overthere you can find many default style of many widgets.

2

and get the file "progress_horizontal.xml". the codes in that file is:

<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

you can easily change the color of the "progress color" and "background color".


Here is what I did to have a progress bar that was green with clear background:

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


 MORE:


 ? "Binary XML file android.widget.ProgressBar cannot be cast to android.view.ViewGroup" in progress bar
 ? "Binary XML file android.widget.ProgressBar cannot be cast to android.view.ViewGroup" in progress bar
 ? "Binary XML file android.widget.ProgressBar cannot be cast to android.view.ViewGroup" in progress bar
 ? cannot display progress bar at the time of loading another Activity in Android
 ? Is there a black progress bar to be visible on a white background?
 ? How to remove progress bar number at the bottom part of the progress bar?
 ? Vertical progress bar in android
 ? Custom indeterminate progress bar
 ? Progress bar inconvertable types; cannot cast error
 ? Remove progress bar from published document in MATLAB