Tuesday, 16 July 2013

Custom background for Progress Bar OR Seek bar in Android

Custom background for Progress Bar in Android

we are using same (AsyncTask with Progress Bar) examlpe for this tutorial.
we just added this progressbar_bg.xml in drawable folder.




<?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 android:shape="rectangle" >
            <corners android:radius="5dp" />

            <gradient
                android:angle="270"
                android:endColor="@color/light_gray_header_color"
                android:startColor="@color/light_gray_header_color" />
        </shape>
    </item>
    <item android:id="@android:id/secondaryProgress">
        <clip>
            <shape android:shape="rectangle" >
                <corners android:radius="5dp" />

                <gradient
                    android:angle="270"
                    android:endColor="#00996a"
                    android:startColor="#00d190" />
            </shape>
        </clip>
    </item>
    <item android:id="@android:id/progress">
        <clip>
            <shape android:shape="rectangle" >
                <corners android:radius="5dp" />

                <gradient
                    android:angle="270"
                    android:endColor="#00996a"
                    android:startColor="#00d190" />
            </shape>
        </clip>
    </item>


</layer-list>


and here is seek bar bg you can use this one also if you need bg for seek bar


<?xml version="1.0" encoding="UTF-8"?>
<inset xmlns:android="http://schemas.android.com/apk/res/android"
    android:insetBottom="1.0px"
    android:insetLeft="1.0px"
    android:insetRight="1.0px"
    android:insetTop="0.0px" >

    <selector>
        <item android:state_pressed="true">
            <shape>
                <gradient
                    android:angle="270.0"
                    android:endColor="@color/rounded_container_bg"
                    android:startColor="@color/rounded_container_bg" />

                <corners android:radius="11.0dip" />
            </shape>
        </item>
        <item>
            <shape>
                <stroke
                    android:width="1.0px"
                    android:color="@color/rounded_container_border" />

                <gradient
                    android:angle="270.0"
                    android:endColor="@color/rounded_container_bg"
                    android:startColor="@color/rounded_container_bg" />

                <corners android:radius="10.0dip" />
            </shape>
        </item>
    </selector>


</inset>


I hope this will helpful.
Happy Codddding :)