android - 使通知大图标圆形

标签 android android-notifications android-5.0-lollipop avatar

我想将用户联系人的圆形头像显示为通知的大图标 - 就像收到短信或邮件时一样。当我将大图标设置为该联系人的图像时,它会生成一个方形图标。

我正在寻找看起来像顶部图标(方形头像),看起来像电子邮件通知上的大图标(圆形头像)的东西:

enter image description here

如何让它变圆?

最佳答案

由于 setLargeIcon() 接受一个 Bitmap,您需要做的就是从源创建一个循环的 Bitmap

以下是来自 Create a circle bitmap in Android 的代码(我自己还没试过)。

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);

    paint.setAntiAlias(true);
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);
    canvas.drawOval(rectF, paint);

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

    bitmap.recycle();

    return output;
}

关于android - 使通知大图标圆形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28280615/

相关文章:

android - 在 singleTask Activity 的 onCreate() 中使用旧的额外内容

android - 解析.com : Sending a localized push notification to Android client - what does the client implementation look like?

android - 未收到通知的 PendingIntent

android - 如何使用Android-L预览任务锁定?

android - 如何在android中实现 'Data Tables'( Material 设计组件)?

java - 发送电子邮件后如何 toast ?

Android 和 TextView 的水平跑马灯滚动率

c# - FindViewById 返回 null(只有一个,在 OnCreate 内部和 SetContentView 之后)

android - 如何以编程方式更改操作栏菜单项的颜色

android - 从广播接收器启动 Activity 时无法访问共享首选项