棒棒糖通知图标太小

9

我正在尝试这段代码,

NotificationCompat.Builder nfBuilder = new NotificationCompat.Builder(
            context)
            ..setContentTitle(
                    "XYZ")
            .setContentText("ABC")
            .setContentIntent(pIntent)
            .setDefaults(Notification.DEFAULT_ALL)
            .setOnlyAlertOnce(true)
            .setAutoCancel(true)
            .setPriority(Notification.PRIORITY_HIGH)
            .setSmallIcon(R.drawable.woj_ic_launcher);

    Notification notification = nfBuilder.build();

    NotificationManager nfManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);

    nfManager.notify(requestCode, notification);

问题是,在所有其他平台上都可以正常工作,但在棒棒糖上,它显示非常小的图标,并带有灰色圆圈。我尝试更改图标大小并使用setLargeIcon()方法,但仍然没有成功。

enter image description here


1
你解决过这个问题吗?我也遇到了同样的问题。 - Japes
暂时不需要。现在我会保持原样。 - Sushant
2
遇到相同的问题。 - A. Adam
我已经尝试解决这个问题两天了,但仍然没有运气。 - Nikola Lajic
1
我遇到了同样的问题。通知栏图标显示正常,但下拉查看完整通知时,图标会像@Sushant描述的那样:小、居中且带灰色背景。尝试使用链接,但没有帮助。尝试了不同的图标大小,但也没有帮助。有什么建议吗? - Federico Alvarez
显示剩余3条评论
2个回答

4

实际上,这是一个正方形的比例和透明的背景。我会查看您建议的工具。如果您提供该工具的链接,我将不胜感激。 - Sushant
@Sushant 不好意思,刚刚编辑了答案,希望能有所帮助。 - Mariano Argañaraz
我会研究一下。除了问题之外,这个气泡背景看起来很棒。你能分享一下你是怎么做到的吗? - Sushant
哈哈,那是我的手机壁纸,你透过通知的透明度看到了它。它是一个雨天时我车窗上的照片。 - Mariano Argañaraz
@Sushant,你能告诉我它是否已经修复了吗?(并标记为正确答案;) - Mariano Argañaraz
1
“setColor”这个提示帮了我很大的忙。现在它虽然小,但不再是灰色的了...谢谢。 - Federico Alvarez

1
这是最终的排序结果:
NotificationCompat.Builder nBuilder = new NotificationCompat.Builder(getApplicationContext());
nBuilder.setContentTitle("notificationTitle");
nBuilder.setSmallIcon(R.mipmap.ic_launcher);
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher1);
nBuilder.setLargeIcon(bitmap);
nBuilder.setContentText(notificationText);

NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(notificationId, nBuilder.build());
  1. 获取一个drawable/mipmap。
  2. 将其转换为位图。
  3. 使用NotificationCompat.BuildersetLargeIcon(Bitmap bitmap)方法设置位图。

注意:在这里,setSmallIcon()是必需的方法。你不能跳过它。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接