Android 通知状态栏和通知正文的不同图标

标签 android push-notification statusbar android-notifications android-notification-bar

我收到了电池电量通知。我想在状态栏和通知中心制作不同的图标。状态栏中:数字(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/

相关文章:

android - 从文档中启用 Android 蓝牙

java - 无法在调用 DatePickerDialog Show 时添加窗口异常

android - Android ImageView 上的抗锯齿圆角

ruby - 无法安装pushmeup插件

android - 构建像纽约时报应用程序一样的 Android 状态栏

当我插入或拔出 USB 键盘时,Android OnConfigurationChanged 不会被调用

android - 对 Google GCM XMPP 感到困惑

ios - 如何在不注册远程静默通知的情况下获取要使用的推送 token ?

ios - 隐藏 iPad 上运行的 iPhone 应用程序的状态栏

Xamarin 表单 : Customize Android Material style status bar color