【问题标题】:Do drawer notification icons have to be white?抽屉通知图标必须是白色的吗?
【发布时间】:2019-05-10 03:02:32
【问题描述】:

我的应用适用于 API 26 或更高版本。

通知中的小图标有问题。 我去了这里的文档,不管我的问题是什么,我看到它提到图标必须是白色的,但是当我现在正在工作时,我正在使用谷歌播客应用程序收听播客,并且图标是彩色的。那么它必须是白色的吗?还是只有谷歌应用才有颜色?

文档链接: https://developer.android.com/guide/practices/ui_guidelines/icon_design_status_bar.html

我的问题是,当抽屉关闭时我的图标出现在顶部(它是彩色谷歌播客图标的绿色图标)。但是当drawe打开时,图标不显示,只是一个空白的绿色圆圈。

这就是我构建通知的方式:

                            Uri notificationSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
                            NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(something, ADMIN_CHANNEL_ID)
                                    .setSmallIcon(R.drawable.logo_fallback)
                                    .setLargeIcon(resource)
                                    .setContentTitle(remoteMessage.getData().get("title"))
                                    .setContentText(remoteMessage.getData().get("message"))
                                    .setAutoCancel(true)
                                    .setSound(notificationSoundUri)
                                    .setContentIntent(pendingIntent);

                            //Set notification color to match your app color template
                            notificationBuilder.setColor(getResources().getColor(R.color.colorPrimaryDark));
                            notificationManager.notify(notificationID, notificationBuilder.build());

我使用的资源是 PNG。我也尝试过 XML,但没有成功。

【问题讨论】:

    标签: android push-notification notifications android-notifications android-notification-bar


    【解决方案1】:

    是的,图标应该是白色的,您必须创建一个具有白色和透明特征的图标并设置应有的背景颜色

    NotificationCompat.Builder b = new NotificationCompat.Builder(ctx,Const.NOTIFICATION_CHANNEL);
    
                b.setAutoCancel(true)
    
                        .setDefaults(Notification.DEFAULT_ALL)
                        .setWhen(System.currentTimeMillis())
                        .setBadgeIconType(R.drawable.logo)
                        .setLargeIcon(BitmapFactory.decodeResource(ctx.getResources(),R.drawable.logo))
                        .setContentTitle(title)
                        .setContentText(message)
                        .setDefaults(Notification.DEFAULT_LIGHTS | Notification.DEFAULT_SOUND)
                        .setContentIntent(contentIntent);
                if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                    b.setSmallIcon(R.drawable.new_logo);
                    b.setColor(ctx.getResources().getColor(R.color.green));
    
                } else {
                    b.setSmallIcon(R.drawable.logo);
                }
    

    这里的 logo 是彩色图标,new_logo 是白色图标

    【讨论】:

    • 谢谢Athira,但我还是对图标有点困惑。例如,如果我查看我放置的示例图像,您会发现信使图标确实是白色的。我可以通过简单地更改 setSmallIcon 中的图标来做到这一点。但是,当通知抽屉被消耗时,Facebook messenger 小图标现在是全蓝色的(我说的是左上角的图标 - 我目前只有一个深绿色圆圈)。那个标志是在哪里声明的?
    • 将要设置颜色的区域设为透明并在 setColor() 中赋予颜色
    • 编辑你的图标,用透明替换彩色区域,并在通知生成器中设置颜色,它看起来像彩色图标
    • 谢谢。我似乎 android 除了所有颜色都没有。当我将其设置为某个绿色时,图标为绿色但不同。例如,如果我尝试某种红色,也是如此。这就像 android 将其设置为允许颜色列表中最接近的颜色。有没有我可以选择的列表?
    猜你喜欢
    • 1970-01-01
    • 2018-12-07
    • 1970-01-01
    • 1970-01-01
    • 2016-01-29
    • 2016-12-20
    • 2016-05-01
    • 2017-03-17
    • 1970-01-01
    相关资源
    最近更新 更多