Android:没有通知图标 [英] Android: No icon for Notification

查看:17
本文介绍了Android:没有通知图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在状态栏中创建一个没有图标的通知(未展开的状态).我尝试了自定义扩展视图并仅为该视图设置了图标.但它没有用.当我将 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;

http://code.google.com/p/quick-settings/source/browse/trunk/quick-settings/src/com/bwx/bquick/receivers/StatusBarIntegrationReceiver.java>

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;

http://code.google.com/p/quick-settings/source/browse/trunk/quick-settings/src/com/bwx/bequick/receivers/StatusBarIntegrationReceiver.java

这篇关于Android:没有通知图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆