首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >安卓推送通知图标LIght主题问题

安卓推送通知图标LIght主题问题
EN

Stack Overflow用户
提问于 2018-07-04 17:04:49
回答 1查看 900关注 0票数 0

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

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

我使用了以下代码:

代码语言:javascript
复制
  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());

获取通知图标方法:-

代码语言:javascript
复制
  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)黑暗主题:-

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-07-04 18:23:59

在所有的搜索和其他事情之后,我找到了我的解决方案,除了通知图标之外,一切都运行得很好,图标保持了一点不同颜色的像素。

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

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51169822

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档