2016-07-22 81 views
0
public void animatedNotification() { 
    NotificationCompat.Builder mBuilder = 
     new NotificationCompat.Builder(context) 
      .setSmallIcon(ic) 
      .setLights(Color.GREEN, 10000, 10000) 
      .setWhen(when) 
      .setPriority(Notification.PRIORITY_HIGH) 
      .setContentTitle(title) 
      .setContentText("Plants Need Watering Some of Your work is pending"); 

    NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); 
    // mId allows you to update the notification later on. 
    mNotificationManager.notify(0, mBuilder.build()); 
} 

回答

1
.setSmallIcon(android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP ? R.mipmap.ic_launcher : R.drawable.notification_icon_bw_xhdpi) 
.setColor(ResourcesCompat.getColor(getResources(), R.color.primary, getTheme())) 

使用顏色區分您的應用程序與其他人。通知圖標應該只是透明背景圖像。 (https://developer.android.com/design/patterns/notifications.html

在lollypop之前,您可以對所有通知圖標使用相同的mipmap圖標。但是從棒棒糖開始,你需要創建新的通知圖標(Silhoette種類的圖標)。

+0

當我更改背景時,整個通知將變爲白色。 –

+0

您需要爲通知創建單獨的圖標,以便在白色背景上呈現良好。 – Ramesh

+0

我在Eclipse上編寫應用程序之前創建它,但現在我們在Android Studio上移動問題出現,.. –

1

由於材質主題用於您的應用notification,小圖標顯示爲白色。

+0

那麼我使用哪個主題? –

相關問題