[英]Notification icon is round white instead of application icon in lollipop
我通过以下代码生成了本地通知。
Notification notification = new Notification.Builder(context)
.setAutoCancel(true)
.setContentTitle("title")
.setContentText("message")
.setWhen(System.currentTimeMillis())
.setSmallIcon(getNotificationIcon())
.build();
private static int getNotificationIcon() {
boolean useWhiteIcon = (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP);
return useWhiteIcon ? R.drawable.icon_loli : R.drawable.ic_launcher;
}
其中icon icon_loli是16 * 16白色图标。 仍然适用于21以下的api版本,它的工作原理非常好,但在棒棒糖上及上面,它将显示通知,如下图所示
这是因为有setSmallIcon()
,并且在材质设计上只有黑色和白色,因为主要目的是在顶部栏中显示统一的图标。 如果需要徽标,则必须使用setLargeIcon()
:
Notification notification = new Notification.Builder(context)
.setAutoCancel(true)
.setContentTitle("title")
.setContentText("message")
.setWhen(System.currentTimeMillis())
.setSmallIcon(getNotificationIcon())
.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher))
.build();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.