Android通知小图标背景一直是黑色

标签 android android-5.0-lollipop android-notifications android-6.0-marshmallow android-statusbar

我使用 NotificationBuilder 为 android 创建了通知,即使我设置了 .setColor(),它也会忽略颜色并将小图标的背景颜色设置为黑色。我的目标 SDK 是 23,最小 SDK 是 19。我用于调试的手机有 Android Marshmallow。感谢您的帮助。

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

Preview

最佳答案

解决了。

而不是 .setColor(R.color.ColorPrime)使用 .setColor(getResources().getColor(R.color.ColorPrime))完全有效。

关于Android通知小图标背景一直是黑色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37865918/

相关文章:

android - 图标未显示在 Android 牛轧糖的通知中

Android Lollipop 联系人检索空指针异常

android - 在首次显示的自定义滑动选项卡 View 中设置文本颜色

android - 在 Android 5.0 上的 Activity 之间转换时如何排除 ActionBar

android - 如何在收到通知时更改 textView 值?

Android:是否可以向扩展 View 添加自定义属性?

java - 我可以获得我的程序剩余多少内存吗?

java - 我的程序在 ListView 中第二次单击时崩溃

Android 和 XML 布局

Android 在通知点击时打开特定的标签 fragment