Android 通知小图标背景常黑
Android notification small icon background is always black
我使用 NotificationBuilder 为 android 创建了通知,即使我设置了 .setColor(),它也会忽略颜色并将小图标的背景色设置为黑色。我的目标 SDK 是 23,最小 SDK 是 19。我用于调试的 phone 有 Android Marshmallow.Thanks 寻求帮助。
.setContentTitle(msgTitle)
.setSmallIcon(R.mipmap.notification_icon)
.setColor(R.color.ColorPrime) // ColorPrime is red.
.setLargeIcon(msgIcon)
.setTicker(msgBody)
.setStyle(new NotificationCompat.BigTextStyle()
.bigText(msgBody).setBigContentTitle(msgTitle))
.setContentText(msgBody)
.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
.setPriority(Notification.PRIORITY_HIGH);
解决了。
而不是 .setColor(R.color.ColorPrime)
使用 .setColor(getResources().getColor(R.color.ColorPrime))
完全有效。
我使用 NotificationBuilder 为 android 创建了通知,即使我设置了 .setColor(),它也会忽略颜色并将小图标的背景色设置为黑色。我的目标 SDK 是 23,最小 SDK 是 19。我用于调试的 phone 有 Android Marshmallow.Thanks 寻求帮助。
.setContentTitle(msgTitle)
.setSmallIcon(R.mipmap.notification_icon)
.setColor(R.color.ColorPrime) // ColorPrime is red.
.setLargeIcon(msgIcon)
.setTicker(msgBody)
.setStyle(new NotificationCompat.BigTextStyle()
.bigText(msgBody).setBigContentTitle(msgTitle))
.setContentText(msgBody)
.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
.setPriority(Notification.PRIORITY_HIGH);
解决了。
而不是 .setColor(R.color.ColorPrime)
使用 .setColor(getResources().getColor(R.color.ColorPrime))
完全有效。