更改通知标题的颜色(Android Studio)

时间:2019-07-06 13:54:05

标签: android android-studio kotlin

那是我的代码,一切正常。

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))仅更改图标颜色。我在文档中没有找到任何内容,如果您查看those images,则标题与图标的颜色相同。所以我不确定错误是由我引起的还是我的代码缺少某些东西?

编辑

标题是应用名称。抱歉,这是我的错误。不是contentTitle,而是应用程序的名称。例如查看those images

1 个答案:

答案 0 :(得分:0)

我在Java中使用这种方法:

int color = ContextCompat.getColor(this, R.color.colorPrimaryDark);
builder.setContentTitle(HtmlCompat.fromHtml("<font color=\"" + color + "\">" + notificationTitle + "</font>", HtmlCompat.FROM_HTML_MODE_LEGACY))
相关问题