Android通知大图标,有没有办法删除右下方的小图标?

zer*_*obe 15 notifications android status

我有一个显示大图的通知.

有没有办法从此视图中删除蜂窝和上方设备中的较小图标?

显然仍然保留顶部状态栏的小图标

在此输入图像描述

   NotificationCompat.Builder builder = new NotificationCompat.Builder(context)


            // Set required fields, including the small icon, the
            // notification title, and text.
            .setSmallIcon(R.drawable.ic_notify_status_new)
            .setContentTitle(title)
            .setContentText(text)


            // All fields below this line are optional.

            // Use a default priority (recognized on devices running Android
            // 4.1 or later)
            .setPriority(NotificationCompat.PRIORITY_DEFAULT)

            // Provide a large icon, shown with the notification in the
            // notification drawer on devices running Android 3.0 or later.
            .setLargeIcon(picture)

            .setContentIntent(
                    PendingIntent.getActivity(
                            context,
                            0,
                            notiIntent,
                            PendingIntent.FLAG_UPDATE_CURRENT)
            );


    builder = getNotiSettings(builder);
    notify(context, builder.build());
Run Code Online (Sandbox Code Playgroud)

Ziv*_*ten 13

生成通知后添加此代码.

   if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        int smallIconViewId = getResources().getIdentifier("right_icon", "id", android.R.class.getPackage().getName());

        if (smallIconViewId != 0) {
            if (notif.contentIntent != null)
                notif.contentView.setViewVisibility(smallIconViewId, View.INVISIBLE);

            if (notif.headsUpContentView != null)
                notif.headsUpContentView.setViewVisibility(smallIconViewId, View.INVISIBLE);

            if (notif.bigContentView != null)
                notif.bigContentView.setViewVisibility(smallIconViewId, View.INVISIBLE);
        }
    }
Run Code Online (Sandbox Code Playgroud)

其中"notif"是您建立的通知,

  • `Notification.contentView.setImageViewResource()`有效,但不推荐使用`contentView`.但是使用`NotificationCompat.Builder.getContentView().setImageViewResource()`(在NotificationCompat.Builder.build()`或`NotificationManager.notify()`之前或之后不起作用 (3认同)

Jea*_*ang 1

只有一种方法:使用自定义布局

您的问题可能是NotificationCompat 4.1 SetSmallIcon和SetLargeIcon的重复