通知LargeIcon设置在中心位置| Android Kotlin

时间:2018-07-28 13:01:09

标签: android kotlin notifications

下面是我的代码,我在Notification中设置了largeIcon(如下图所示),但是无法在Icon View的中心设置图标。我使用了下面的代码,但没有解决我的错误。预先感谢。

var mBuilder = NotificationCompat.Builder(this)
mBuilder.setLargeIcon(getCircleBitmap(it))

=======================

private fun getCircleBitmap(bitmap: Bitmap): Bitmap {
    val output = Bitmap.createBitmap(96,96, Bitmap.Config.ARGB_8888)
    val canvas = Canvas(output)
    val color = Color.parseColor("#f1f2f5")
    val paint = Paint()
    val rect = Rect(0, 0, 96, 96)
    val rectF = RectF(rect)
    paint.isAntiAlias = true
    canvas.drawARGB(0, 0, 0, 0)
    paint.color = color
    canvas.drawOval(rectF, paint)
    paint.xfermode = PorterDuffXfermode(PorterDuff.Mode.SRC_IN)
    canvas.drawBitmap(bitmap, rect, rect, paint)
    bitmap.recycle()
    return output
}

enter image description here

0 个答案:

没有答案