2017-06-02 24 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