2017-04-03 28 views
0

我使用以下代碼獲取Notificaiton圖標。這給出了正常的通知圖標,但在其右下角有一個小白盒。我怎樣才能爲此設置圖標。在通知圖標中添加小圖標

public void not() { 
     Notification noti = new Notification.Builder(context).setSmallIcon(R.mipmap.lnc) 
       .setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.mipmap.lnc)) 
       .setContentTitle("My Title") 
       .setContentText("Done").setSmallIcon(R.mipmap.lnc) 
       .build(); 
     NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); 
     // hide the notification after its selected 
     noti.flags |= Notification.FLAG_AUTO_CANCEL; 

     notificationManager.notify(0, noti); 
    } 

回答

0

棒棒糖起,你的小圖標必須爲單色即透明背景&白色的,否則它會顯示爲白色框。因此,將您的R.mipmap.lnc轉換爲剪影,即創建您的圖標,以便您要顯示的部分應該是白色的&背景是透明的。如果你想添加一種顏色到背景,你可以使用setColor方法來完成。

閱讀this鏈接。

+0

所以我有一個主圖標,然後在右下角,並在一個白色的盒子一圈。 Setcolor將圓圈的顏色從默認的灰色設置爲所選的顏色,儘管白色框保持白色。 – Panache

+0

不會有任何白盒,那麼會有一個背景顏色設置的圓圈,裏面會是你創建的白色圖標。 –

+0

是的,實際上我使用的是mipmap圖標而不是可繪製的。現在我可以看到我的小圖標。 – Panache

2

使用​​)設置通知的小圖標。

供參考,根據設計指南,您必須使用silhouetteBuilder.setSmallIcon()。見design gideline

Notification noti = new Notification.Builder(context) 
      .setSmallIcon(getNotificationSmallIcon()) 
      .setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.mipmap.lnc)) 
      .setContentTitle("My Title") 
      .setContentText("Done") 
      .build(); 

.................. 
.......................... 

private int getNotificationSmallIcon() { 
    boolean useWhiteIcon = (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP); 
    return useWhiteIcon ? R.drawable.ic_silhouette : R.drawable.ic_launcher; 
} 
0
 NotificationCompat.Builder mNotifyBuilder; 

mNotifyBuilder = new NotificationCompat.Builder(context) 
       .setContentTitle("Captian Mansoura") 
       .setContentText("Busy , On trip Now") 
      .setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.mipmap.lnc)) 

       .setSmallIcon(R.mipmap.notify_offline); 

試試這個