Android通知小图标背景始终是黑色的

Tun*_*dır 2 android android-notifications android-5.0-lollipop android-statusbar android-6.0-marshmallow

我用NotificationBuilder为android创建了通知,虽然我设置了.setColor(),它忽略了颜色并将小图标的背景颜色设置为黑色.我的目标SDK是23,min SDK是19.而我用于调试的手机有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);
Run Code Online (Sandbox Code Playgroud)

预习

Tun*_*dır 7

解决了它.

而不是.setColor(R.color.ColorPrime)使用.setColor(getResources().getColor(R.color.ColorPrime))完全工作.