2017-06-02 64 views
0

由于android棒棒糖通知图标应该是白色的。有颜色的通知,我已覆盖图像&设定背景为绿色:初始通知是彩色的,然后是白盒通知?

初始通知来了颜色为绿色,如下:

enter image description here

但一段时间的通知后,来到白牌:

enter image description here

这里有什么不对吗?

守则如下:

Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); 
     NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) 
       .setContentTitle(title) 
       .setContentText(messageBody) 
       .setAutoCancel(true) 
       .setSound(defaultSoundUri) 
       .setContentIntent(pendingIntent); 

      notificationBuilder 
        .setSmallIcon(R.drawable.notify1) 
        .setColor(Color.GREEN);  

     NotificationManager notificationManager = 
       (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 
     notificationManager.notify(SERVER_NOTIFICATION_ID, notificationBuilder.build()); 

我使用的图像是如下:

enter image description here

回答

2

试试这个::

if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.LOLLIPOP) { 
     notificationBuilder 
       .setSmallIcon(R.drawable.notify1) 
       .setColor(Color.GREEN);  
    } else { 
     notificationBuilder 
       .setSmallIcon(R.drawable.notify1) 
       .setColor(Color.GREEN);  
    } 
+0

请告诉我这里的优势if和else都执行相同的代码行? – pcj

+0

根据Android设计指南,您必须使用轮廓,但您有黑色的图标,这就是为什么您需要明确设置为棒棒糖和以上。 – Jaymin