通知栏同时显示大图标和小图标

6

我的应用程序中的通知栏仅在滚动条中显示小图标(应该如此)。但是,当“下拉”时,它将同时显示来自滚动条的小图标和我在Notification.Builder中设置的大图标。这是我的代码:

if (Build.VERSION.SDK_INT > 10){
            notification = new Notification(R.drawable.ic_stat_mintchip,
                    "This is a test",
                    System.currentTimeMillis());
            notification.largeIcon = (((BitmapDrawable)c.getResources().getDrawable(R.drawable.ic_launcher)).getBitmap());
            notification.defaults |= Notification.DEFAULT_ALL;
            notification.number += 1;
            notification.flags |= Notification.FLAG_AUTO_CANCEL;

        } else {
            notification = new Notification(R.drawable.ic_stat_mintchip,
                    "This is a test",
                    System.currentTimeMillis());

                notification.flags |= Notification.FLAG_AUTO_CANCEL;
                notification.defaults |= Notification.DEFAULT_ALL;
                notification.number += 1;
        }
}

我不太清楚为什么会发生这种情况。有什么帮助吗?

1
你能否在某个地方发布一张你所看到的屏幕截图? - CommonsWare
好的,稍等一下... http://imgur.com/07lxg - D4N14L
1
我假设你是MintChip。我不太确定为什么会出现这种效果。这是什么设备?请注意,虽然你的问题中提到你正在使用Notification.Builder,但是你的代码并没有使用它。你可以考虑使用来自Android支持库项目的NotificationCompat.Builder,看看是否有所帮助。 - CommonsWare
3个回答

11

我认为这里的问题可能是您没有使用Notification.Builder类。以下是一个小例子,您可以参考(当然需要插入自己的变量,并设置您所使用的其他属性,例如振动):

Notification.Builder nb = new Notification.Builder(context)
    .setContentTitle("title")
    .setContentText("content")
    .setAutoCancel(true)
    .setLargeIcon(largeIcon)
    .setSmallIcon(R.drawable.small_icon)
    .setTicker(s.getText());
NotificationManager nm = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
nm.notify(100, nb.build());

1
我无法在Android4.04中编译'nb.build()',我改用了'nb.getNotification()'。 - herbertD
如果我使用滚动文本,它会使用哪个图标?我如何自定义并为其使用不同的图标以及通知本身的不同图标? - android developer
@androiddeveloper 小图标显示在状态栏中,大图标在打开通知栏时显示。 - afollestad
@afollestad 是否可以为滚动文本和通知分别设置不同的图标? - android developer
1
使用上述代码,如果我设置了小图标和大图标,当用户拉出通知时,通知会同时显示小图标和大图标。在以下配置下运行:<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="24" />有什么解决方案吗? - ashok reddy

7

我在安卓棒棒糖系统中遇到的另一个问题是,小图标显示在大图标旁边。要解决这个问题,只需要不设置大图标!仅使用小图标设置即可。


1
但是我想同时使用两者,有什么办法吗? - Vedant Agarwala
如果您设置了两个图标,那么两个图标都会出现。 - ravyoli

0

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