首页 > 解决方案 > Android 推送通知图标 LIght 主题问题

问题描述

我知道这个问题被问了很多次与推送通知状态栏图标有关,但我的问题有点不同。

我正在使用 FCM 推送通知,我的通知正常发送。我已经为 pre-lollipop 和更多的棒棒糖版本设置了通知图标。我的通知图标在 MOTO-G 5+ 等深色主题设备中正常显示,但是当我在三星 Galaxy Edge 7.0 等浅色主题设备上查看相同通知时,我的通知图标根据应用主题变为白色,但在另一个应用中,通知图标看起来正常。我看到了许多示例解决方案,但它们对我的问题没有帮助。

我正在使用以下代码:

  PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ila_app_icon);
    long when = System.currentTimeMillis();

    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this);
    notificationBuilder.setContentText(message)
            .setContentIntent(pendingIntent)
            // .setColor(getNotificationColor())
            .setSmallIcon(getNotificationIcon(notificationBuilder))
            .setWhen(when)
            .setSound(defaultSoundUri)
            .setLargeIcon(bitmap);

    Random random = new Random();
    int uniqueIntegerNumber = random.nextInt(9999 - 1000) + 1000;
    notificationManager.notify(uniqueIntegerNumber, notificationBuilder.build());

获取通知图标方法:-

  private int getNotificationIcon(NotificationCompat.Builder notificationBuilder) {

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        int color = 0x008000;
        notificationBuilder.setColor(color);
        return R.drawable.notification_white;

    }
    return R.drawable.ila_app_icon;
}

我也尝试了setColor属性,但这也不起作用。

1)轻主题 (这里是白旗图标)

在此处输入图像描述 这是屏幕截图:-

在此处输入图像描述

2)黑暗主题:-

在此处输入图像描述

标签: androidpush-notification

解决方案


经过所有搜索和其他事情后,我找到了我的解决方案,一切正常,除了通知图标,图标保持着不同颜色的一点点像素。

我们可以从以下链接创建通知图标,它使我们的图标对通知透明

https://romannurik.github.io/AndroidAssetStudio/icons-notification.html#source.type=clipart&source.clipart=ac_unit&source.space.trim=1&source.space.pad=0&name=ic_stat_ac_unit


推荐阅读