How to create a battery level indicator in android?
<p><a href="https://i.stack.imgur.com/Rb9qr.png" rel="nofollow"><img src="https://i.stack.imgur.com/Rb9qr.png" alt="enter image description here"></a></p>

<p>I want to create a battery level indicator as in the image(which i circled). The green part should fill based on the available battery in the device.</p>

<p>Getting the battery percentage from the device like this</p>

<pre><code>registerReceiver(mBatInfoReceiver, new IntentFilter(
            Intent.ACTION_BATTERY_CHANGED));
</code></pre>

<p>So in the layout i am able to display the battery percentage.</p>

<pre><code>public class BatteryIndicatorActivity extends Activity {
        //Create Broadcast Receiver Object along with class definition
    private BroadcastReceiver mBatInfoReceiver = new BroadcastReceiver() {
        @Override
          //When Event is published, onReceive method is called
        public void onReceive(Context c, Intent i) {
              //Get Battery %
            int level = i.getIntExtra("level", 0);
            TextView tv = (TextView) findViewById(R.id.textfield);
              //Set TextView with text
            tv.setText("Battery Level: " + Integer.toString(level) + "%");
        }

    };
</code></pre>

<p>But how to create a UI for this type of battery indicator. Is their any api to achieve this?, If not how to create such type of UI.</p>

<p>Your help will be appreciated.</p>