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

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

问题描述

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

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:

< a href =https://i.stack.imgur.com/tYmdz.jpg =noreferrer>

如何复制此内容?我需要设置哪些属性?

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天全站免登陆