Android 颜色通知图标 [英] Android Color Notification Icon

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

问题描述

我正在开发一个应用程序,我在其中为用户创建通知.我希望图标在状态栏中显示为白色,但在下拉通知菜单中显示时显示为蓝色.以下是 Google 商店应用执行相同操作的示例.

I'm working on an app where I create a notification for the user. I want the icon to appear as white when it's in the status bar, but colored blue when it's being displayed in the drop down notification menu. Here's an example of the same thing being done by the Google Store app.

状态栏中的白色通知:

下拉菜单中的彩色通知:

Colored notification in drop down menu:

我怎样才能复制这个?我必须设置哪些属性?

How can I replicate this? What properties do I have to set?

这是我当前的代码 - 我将图像设为全白色并带有透明背景,因此在状态栏中看起来不错,但在通知下拉菜单中,图像仍然是相同的白色:

Here's my current code - I made the image all white with a transparent background, so it looks fine in the status bar, but in the notification drop, the image is still the same white color:

private NotificationCompat.Builder getNotificationBuilder() {
        return new NotificationCompat.Builder(mainActivity)
                .setDeleteIntent(deletedPendingIntent)
                .setContentIntent(startChatPendingIntent)
                .setAutoCancel(true)
                .setSmallIcon(R.drawable.skylight_notification)
                .setColor(ContextCompat.getColor(mainActivity, R.color.colorPrimary))
                .setContentTitle(mainActivity.getString(R.string.notification_title))
                .setContentText(mainActivity.getString(R.string.notification_prompt));
    }

推荐答案

我在这里找到了我的问题的答案:https://stackoverflow.com/a/44950197/4394594

I found the answer to my question here: https://stackoverflow.com/a/44950197/4394594

我不完全知道问题是什么,但是通过将我用于图标的巨大 png 放入这个工具 https://romannurik.github.io/AndroidAssetStudio/icons-notification.html#source.type=image&source.space.trim=1&source.space.pad=0&name=ic_skylight_notification并将生成的图标放入我的 mipmap 文件夹中,我能够使 setColor(...) 属性正常工作.

I don't know entirely what the problem was, but by putting the huge png that I was using for the icon into the this tool https://romannurik.github.io/AndroidAssetStudio/icons-notification.html#source.type=image&source.space.trim=1&source.space.pad=0&name=ic_skylight_notification and by placing the generated icons it gave into my mipmap folder, I was able to get the setColor(...) property to work correctly.

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

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