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

NotificationCompat android - how to show only Large icon without small

当我添加通知时:

        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);

我看到大图标和小图标:

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

必须使用小图标。 如果您不设置大图标,您会在圆圈中间使用您选择的颜色 (setColor) 使小图标变大。

如果我是你,我会把空白的 E 放在小图标的透明背景上,并为圆圈设置红色。

获取小图标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);
}

试着看看这个post它也会有帮助

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

根据之前的回答,您还可以将展开的视图隐藏到:

int smallIconId = AnghamiApp.getContext().getResources().getIdentifier("right_icon", "id", android.R.class.getPackage().getName());
            if (smallIconId != 0) {
                notification.contentView.setViewVisibility(smallIconId, View.INVISIBLE);
                notification.bigContentView.setViewVisibility(smallIconId, View.INVISIBLE);
            }

您可以创建自定义通知,然后在大通知区域中显示您想要的任何内容。 请参阅此处示例 TutorialsFace: Build all types of Notifications in Android

public class MainActivity extends AppCompatActivity {
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Notification notification = new NotificationCompat.Builder(this)
            .setContentTitle("Test")
            .setContentText("Hii There")
            .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.smallicon))
            .setAutoCancel(true)
            .build();
    NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
    notificationManager.notify(123, notification);
  }
}