如何在状态栏中创建没有图标的通知或只是隐藏它? [英] How to create a notification without icon in the statusbar or simply hide it?
本文介绍了如何在状态栏中创建没有图标的通知或只是隐藏它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道如何创建一个不会在状态栏中显示图标的通知。
I'd like to know how to create a notification that doesn't show the icon in the statusbar.
有一种方法可以隐藏它吗?
There is a way to hide it?
推荐答案
从Android 4.1(API级别16)开始,可以指定通知的 priority
。如果您将该标记设置为 PRIORITY_MIN
通知图标不会显示在状态栏上。
Since Android 4.1 (API level 16) it's possible to specify a notification's priority
. If you set that flag to PRIORITY_MIN
the notification icon won't show up on the statusbar.
notification.priority = Notification.PRIORITY_MIN;
或者如果您使用 Notification.Builder
:
builder.setPriority(Notification.PRIORITY_MIN);
从Android 8.0 Oreo开始(API级别26)您必须将通知的 NotificationChannel
的重要性
设置为 IMPORTANCE_MIN
:
As of Android 8.0 Oreo (API level 26) you have to set the importance
of the notification's NotificationChannel
to IMPORTANCE_MIN
:
NotificationChannel channel =
new NotificationChannel(channelId, channelName, NotificationManager.IMPORTANCE_MIN);
notificationManager.createNotificationChannel(channel);
...
builder.setChannelId(channel.getId())
这篇关于如何在状态栏中创建没有图标的通知或只是隐藏它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文