[英]Seperate Notification icon for status bar and main notiffication
使用此代碼構建通知。
Notification.Builder nb = new Notification.Builder(context)
.setContentTitle("title")
.setContentText("content")
.setAutoCancel(true)
.setColor(ContextCompat.getColor(context, R.color.ANYCOLOR))
.setLargeIcon(largeIcon)
.setSmallIcon(small_icon)
.setTicker(s.getText());
NotificationManager nm = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
nm.notify(100, nb.build());
在此代碼中,您必須替換小圖標和大圖標。
您可以設置顏色使用
.setColor(getResources().getColor(R.color.yourcolor))
而完整的代碼看起來像
Notification.Builder nb = new Notification.Builder(context)
.setContentTitle("title")
.setContentText("content")
.setAutoCancel(true)
.setColor(getResources().getColor(R.color.primary))
.setLargeIcon(largeIcon)
.setSmallIcon(small_icon)
.setTicker(s.getText());
NotificationManager nm = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
nm.notify(100, nb.build());
希望這對你有所幫助
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.