Itai Hanski Itai Hanski - 1 year ago 248
Android Question

Make Notification Large Icon Round

I want to display a circular avatar from the user's contacts as the large icon of the notification - like when receiving a text or mail. When I set the large icon as that contact's image, it results in a square icon.

I'm looking to turn something that looks like the top icon (the square avatar), look like the large icon on the email notification (the round avatar):

enter image description here

How do I make it round?

Answer Source

Since setLargeIcon() accepts a Bitmap, all you need to do is create a circular Bitmap from the source.

Following is the code from Create a circle bitmap in Android (haven't tried myself).

private Bitmap getCircleBitmap(Bitmap bitmap) {
    final Bitmap output = Bitmap.createBitmap(bitmap.getWidth(),
            bitmap.getHeight(), Bitmap.Config.ARGB_8888);
    final Canvas canvas = new Canvas(output);

    final int color = Color.RED;
    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
    final RectF rectF = new RectF(rect);

    canvas.drawARGB(0, 0, 0, 0);
    canvas.drawOval(rectF, paint);

    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect, paint);


    return output;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download