0

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..

indraja machani
  • 679
  • 1
  • 9
  • 25

1 Answers1

1

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

Kalai.G
  • 1,610
  • 13
  • 22
  • Hi I have already gone through this blog.I have status but the thing is i need to show it in progress bar.I am able show it in normal progress bar kind of thing But I am unable to show it in the way how I want.Thanks.. – indraja machani Oct 07 '13 at 11:03
  • http://www.techrepublic.com/blog/app-builder/androids-batterymanager-and-progressbar-two-for-one-tutorial/703, http://android.programmerguru.com/android-broadcast-receiver-example/ try these – Kalai.G Oct 07 '13 at 11:09