首页 > 解决方案 > 抽屉通知图标必须是白色的吗?

问题描述

我的应用程序适用于 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,但没有成功。

标签: androidpush-notificationnotificationsandroid-notificationsandroid-notification-bar

解决方案


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

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 是白色图标


推荐阅读