Progressbar change background and fore color – Android sample

MainActivity.java

        ProgressBar mProgressBarScore;
      // onCreate
	mProgressBarScore = (ProgressBar)findViewById(R.id.progressBarScore);
	Resources res = getResources();
	mProgressBarScore.setProgressDrawable(res.getDrawable( R.drawable.my_progress));

res/layout/main.xml

       <ProgressBar
            android:id="@+id/progressBarScore"
            style="?android:attr/progressBarStyleHorizontal"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" android:max="100"/>

res/drawable/my_progress.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
 
<item android:id="@android:id/background">
    <shape>
        <!-- radius background of progressbar -->
        <corners android:radius="10dip" />
        <gradient
                android:startColor="#FF001A"
                android:centerColor="#ff5a5d5a"
                android:centerY="0.75"
                android:endColor="#FF001A"
                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>
            <!-- radius of secundary progress -->
            <corners
                android:radius="10dip" />
            <gradient
                android:startColor="#00ff00"
                android:centerColor="#80ffb600"
                android:centerY="0.75"
                android:endColor="#339900"
                android:angle="270" />
        </shape>
    </clip>
</item>
 
</layer-list>
This entry was posted in Android Examples Code and tagged , . Bookmark the permalink.


Comments are closed.



29,506 views