NotificationCompat android - 如何只显示大图标而不是小

Wal*_*est 12 notifications android

当我添加通知时:

        NotificationCompat.Builder mBuilder =
                            new NotificationCompat.Builder(this)  
              .setSmallIcon(R.drawable.plus)
.setContentTitle(title)
.setAutoCancel(true) 
.setContentText(text)
.setSound(RingtoneManager .getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
.setLargeIcon(bm);
Run Code Online (Sandbox Code Playgroud)

我看到大图标和小图标: 在此输入图像描述

如何只设置大图标,不小.如果只使用setLargeIcon,我根本看不到通知,只是声音警报.

小智 15

小图标是强制性的.如果你没有设置一个大的,你会在你选择的颜色(setColor)的圆圈中间放大你的小图标.

如果我是你,我会把那个空白的E放在透明的背景上为小人,并为圆圈设置一个红色.


Sha*_*ihi 9

获取小图标ID,然后尝试隐藏它

int smallIconId = ctx.getResources().getIdentifier("right_icon", "id", android.R.class.getPackage().getName());
if (smallIconId != 0) { 
    if (notification.contentView!=null)
        notification.contentView.setViewVisibility(smallIconId, View.INVISIBLE);
}
Run Code Online (Sandbox Code Playgroud)

试着看这篇文章也会有所帮助

我在api 18,23(三星j1,galaxy S6)上测试代码工作正常

  • 注意:小图标是必需的,这意味着你应该设置值,但你可以尝试上面的代码隐藏小图标,... (2认同)