indraja machani
indraja machani

Reputation: 679

Show custom progressbar in android

I want to show a custom progress-bar, which represents the battery charged status like 25%, 50% etc and that should look like as follows...Please help me thanks in advance

enter image description here

I have tried the following coding..

drawable/custom_progressbar.xml is as follows..

<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:id="@android:id/background">
    <shape android:shape="rectangle" >
        <corners android:radius="25dip" />

        <gradient
            android:centerColor="@android:color/black"
            android:endColor="@android:color/black"
            android:gradientRadius="200"
            android:startColor="@android:color/black"
            android:type="radial" />
    </shape>
</item>

<item android:id="@android:id/secondaryProgress">
<clip>
    <shape>
        <corners android:radius="25dip" />
        <gradient
                android:startColor="@android:color/white"
                android:centerColor="@android:color/white"
                android:centerY="0.75"
                android:endColor="@android:color/white"
                android:angle="270"
        />
    </shape>
</clip>

Then used the above progressbar as follows in my battery_status.xml as follows..

 <ProgressBar android:id="@+id/battery_pb"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:minWidth="262dip"
                android:minHeight="100dip"
                android:max="100"
                android:layout_marginLeft="0dip"
                android:layout_marginRight="21dp"
                style="?android:attr/progressBarStyleHorizontal"
                android:progressDrawable="@drawable/custom_progressbar"/> 

But I didn't get the way how I want my progressbar so please help me..

Upvotes: 0

Views: 4270

Answers (1)

Kalai.G
Kalai.G

Reputation: 1610

Calculate the battery status with percentage ratio.Try to set battery level to progressBar Status like progressBar.setProgress(battery level);

This link may help you http://learnandroideasily.blogspot.in/2013/05/customizing-progress-bar-in-android.html

Upvotes: 1

Related Questions