我收到了电池电量通知。我想在状态栏和通知中心制作不同的图标。状态栏中:数字(2 位)。在正文中:我的应用程序图标。 我怎样才能做到这一点?应用程序图标也在状态栏中,我该如何更改它?
最佳答案
我不确定你的代码现在是什么样子,但我会做这样的事情:
Notification.Builder nb = new Notification.Builder(context)
.setContentTitle("title")
.setContentText("content")
.setAutoCancel(true)
.setLargeIcon(R.drawable.large_icon)
.setSmallIcon(R.drawable.small_icon)
.setTicker("ticker text");
NotificationManager nm = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
nm.notify(100, nb.build());
注意setLargeIcon()
和setSmallIcon()
。您想要在“股票代码”中显示的图标应在 setSmallIcon()
中设置,对于您所谓的“通知中心”,您应该使用 setLargeIcon()
。这应该可行。
关于Android 通知状态栏和通知正文的不同图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22336456/