Android:没有通知图标 [英] Android: No icon for Notification
问题描述
我想在状态栏中创建一个没有图标的通知(未展开的状态).我尝试了自定义扩展视图并仅为该视图设置了图标.但它没有用.当我将 0 作为图标给构造函数时,图标消失但通知也不会出现在展开的视图中.
通知通知 = new Notification(0, "", 0);
我尝试了很多组合,但没有找到解决方案.顺便说一下,我知道它是有效的,因为我在一些应用程序中看到了这个功能.谢谢.
QuickSettings 做到了这一点,当我查看该代码时,我看到它使用 Notification 的默认构造函数并将其图标推送到通知栏的右侧.我认为它仍然使用空间但没有图标.
一些代码:
notification = new Notification();Notification.flags |= Notification.FLAG_ONGOING_EVENT;Notification.flags |= Notification.FLAG_NO_CLEAR;long hiddenTime = Constants.SDK_VERSION >= 9 ?-Long.MAX_VALUE : Long.MAX_VALUE;通知.when = 可见?System.currentTimeMillis() : hiddenTime;//对齐//状态栏中的左(0)/右(最大)
哦,对不起,我错过了重要的一行代码,事实上他使用了占位符.但是现在你有了一些代码 ;-)
notification.icon = 可见 ?(状态 == Constants.STATUS_BLACK_ICON ?R.drawable.ic_logo_black : R.drawable.ic_logo_white): R.drawable.ic_placeholder;
I wanted to create a notification without the icon in the status bar (the state that is not expanded). I tried the custom expanded view and set the icon for this view only. But it did not work. When I give 0 as icon to the constructor, the icon disappears but notification also does not appear in the expanded view.
Notification notification = new Notification(0, "", 0);
I tried a lot of combinations but didn't come out with a solution. By the way, I know it is working because I saw this feature in some apps. Thanks.
QuickSettings did this and as I looked at that code I saw it uses the default constructor of Notification and pushes its icon to the right of the notification bar. I think it still uses space but has no icon.
Some code:
notification = new Notification();
notification.flags |= Notification.FLAG_ONGOING_EVENT;
notification.flags |= Notification.FLAG_NO_CLEAR;
long hiddenTime = Constants.SDK_VERSION >= 9 ? -Long.MAX_VALUE : Long.MAX_VALUE;
notification.when = visible ? System.currentTimeMillis() : hiddenTime; // align
// left (0) / right (max) in status bar
edit: oh sorry I missed an important line of code, in fact he uses a placeholder. But now you have some code ;-)
notification.icon = visible ? (status == Constants.STATUS_BLACK_ICON ?
R.drawable.ic_logo_black : R.drawable.ic_logo_white)
: R.drawable.ic_placeholder;
这篇关于Android:没有通知图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!