Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 491
QuinnChen Avatar asked May 12 '15 04:05

QuinnChen


1 Answers

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"
like image 63
Droid Chris Avatar answered Sep 19 '22 03:09

Droid Chris