更改通知标题的颜色(Android) [英] Change color of notification title (Android)

查看:424
本文介绍了更改通知标题的颜色(Android)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

That's my code and everything works fine.

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

The only problem is I can't change the color of the title (= "Hello World"). The last line .setColor(ContextCompat.getColor(this, R.color.colorPrimaryDark)) changes only the icon-color. I found nothing in the documentation and if you look at those images, you see the title have the same color as the icon. So I'm not sure if the error comes from me or my code missing something?

编辑

标题是应用名称.抱歉,这是我的错误.不是contentTitle,而是应用程序的名称.检查例如那些图像.

With title I mean the app name. Sorry, it was my mistake. Not the contentTitle, but the name of the app. Check for example those images.

推荐答案

我正在Java中使用这种方法:

I'm using this approach in Java:

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

这篇关于更改通知标题的颜色(Android)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆