在Lollipop系统中,通知图标未显示在状态栏中。

4

这是我用来显示通知的代码。

notification = new Notification.Builder(context).setContentIntent(contentIntentTwo)
                        .setContentTitle("App name").setSmallIcon(R.drawable.ic_launcher).setLargeIcon(notificationLargeIconBitmap).getNotification();

通知和通知图标会在下拉通知抽屉中显示,但在棒棒糖(Lollipop)中不会在状态栏中显示。以下是棒棒糖中的情况:
enter image description here
只有在棒棒糖中出现这种情况。

如果你在其他地方找到更好的解决方案,贴上链接是个好主意。对于其他人来说,原始提问者在这里问了同样的问题,并得到了更好的答复:http://www.reddit.com/r/androiddev/comments/2qjsal/notification_icon_shows_in_white_in_status_bar/ - Nirmal
2个回答

2

所以,我只需要使用 setcolor() 函数吗?你能再多提供一些细节吗?我刚刚阅读了文档,但唯一的结论就是使用 setcolor 函数。 - user4351462
系统会忽略动作图标和主通知图标中的所有非 alpha 通道。您应该假设这些图标仅包含 alpha 通道。系统会以白色绘制通知图标,以深灰色绘制动作图标。 - tachyonflux
@karaokyo - 我应该怎么做才能让图标可见?它应该有透明背景,但这就足够了吗? - Rat-a-tat-a-tat Ratatouille
1
@Rat-a-tat-a-tat Ratatouille 你不行。Lollipop会用白色覆盖层遮盖它。你的图标应该有独特的形状。 - tachyonflux
1
这里有一个通知设计文档:http://developer.android.com/design/patterns/notifications.html http://developer.android.com/design/style/iconography.html#notification - tachyonflux
显示剩余3条评论

0

对于Android系统5.0以下版本,您仍然可以使用drawable图像。但是对于Android 5.0及以上版本,您需要使用透明背景图像作为通知图标(最好是PNG格式)。我知道,Android 5.0及以上版本会将任何非透明颜色转换为白色,以实现简单和“肤色减少”理念,以符合Material Design的要求。

NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
            .setContentTitle(title)
            .setContentText(body)
            .setPriority(2)
            .setContentIntent(pendingIntent);
    mBuilder.setAutoCancel(true);
    if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP){
        mBuilder.setSmallIcon(R.mipmap.ic_launcher_transparant);
    }else{
        mBuilder.setSmallIcon(R.mipmap.ic_launcher);
    }

https://medium.com/swarm-nyc/complexion-reduction-a-new-trend-in-mobile-design-cef033a0b978#.fblfw0ohi


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接