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

D4N*_*14L 6 notifications android android-notifications android-notification-bar

我的应用程序中的通知栏仅显示自动收报机中的小图标(应该如此).但是,当"阴影"被拉下时,它会显示自动收报机中的小图标,以及我在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;
        }
}
Run Code Online (Sandbox Code Playgroud)

我不太清楚为什么会这样.任何帮助?

afo*_*tad 11

我认为这里的问题可能是你没有使用Notificaiton.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());
Run Code Online (Sandbox Code Playgroud)


rav*_*oli 7

我在android lollipop中遇到的另一个问题是小图标显示在大图标旁边.解决它 - 只是不要设置大图标!仅使用小图标设置.

  • 请参阅http://stackoverflow.com/a/33943309/218473,了解如何隐藏小图标 (3认同)