抽屉式通知图标必须为白色吗?

时间:2019-05-10 03:02:32

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

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

通知中的小图标出现问题。 我去了这里的文档,无论我遇到什么问题,我都看到它必须是白色的图标,但是由于我现在正在工作,所以我正在使用Google Podcast应用程序收听Podcast,并且该图标是彩色的。那么它是否必须是白色?还是只有Google应用程序可以具有颜色?

enter image description here

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

我的问题是,当抽屉关闭时,我的图标显示在顶部(绿色google播客图标旁边的绿色图标)。但是,当打开抽屉时,该图标不会显示,而只是一个绿色的空白圆圈。

enter image description here

这是我构建通知的方式:

                            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,但没有成功。

1 个答案:

答案 0 :(得分:0)

是的,图标应为白色,您必须创建具有白色和透明功能的图标并设置应有的背景色

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);
            }

此处徽标为彩色图标,而new_logo为白色图标