这是我的代码,一切正常。
val builder = NotificationCompat.Builder(this, "NOTI_ID")
.setSmallIcon(R.drawable.ic_stat_name)
.setContentTitle("My notification")
.setContentText("Hello World!")
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setContentIntent(pendingIntent)
.setAutoCancel(true)
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
.setColor(ContextCompat.getColor(this, R.color.colorPrimaryDark))
唯一的问题是我无法更改标题的颜色(=“Hello World”)。最后一行.setColor(ContextCompat.getColor(this, R.color.colorPrimaryDark))
仅更改图标颜色。我在文档中找不到任何内容,如果您查看那些图像 https://developer.android.com/training/notify-user/build-notification#reply-action,您会看到标题与图标的颜色相同。所以我不确定错误是来自我还是我的代码丢失了某些东西?
EDIT
标题是指应用程序名称。抱歉,这是我的错误。不是内容标题,而是应用程序的名称。检查例如那些图像 https://developer.android.com/training/notify-user/build-notification#reply-action.
我在 Java 中使用这种方法:
int color = ContextCompat.getColor(this, R.color.colorPrimaryDark);
builder.setContentTitle(HtmlCompat.fromHtml("<font color=\"" + color + "\">" + notificationTitle + "</font>", HtmlCompat.FROM_HTML_MODE_LEGACY))
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)