Vajira Lasantha Vajira Lasantha - 3 months ago 10x
Android Question

Android Widget Arc Progress [FIXED]

FIXED: Updated answer is below.

In my android app I got few widgets and I want them to look like these progress bars.

enter image description here

Now I know that I can not use any external libs to do this as widgets dont support most of the custom views. I have seen most developers use bitmap to draw things like this. I can manage to draw a full circle. But how can I draw this arc shape progress bar using bitmap or is there any other way?

Appreciate your help. Thanks!


Yes, you need a bitmap but it's easy enough to draw an arc on a bitmap the same way you would draw an arc on a custom view:

    Bitmap bitmap = Bitmap.createBitmap(width, height, Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    canvas.drawArc(arcRect, startAngle, sweepAngle, false, paint);

    RemoteViews views = new RemoteViews(updateService.getPackageName(), R.layout.widget);
    views.setImageViewBitmap(, bitmap);