我知道要支持棒棒糖材質設計指南,我們必須將通知圖標設置爲透明。通知欄圖標在Android中從FCM變成白色
這是我的FCM onMessageReceived()函數顯示通知。
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
NotificationCompat.Builder mBuilder;
mBuilder = new NotificationCompat.Builder(this)
.setContentTitle(remoteMessage.getNotification().getBody()) // title for notification
.setContentText(remoteMessage.getNotification().getTitle()) // message for notification
.setDefaults(Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND)
.setSmallIcon(getNotificationIcon())
.setAutoCancel(true); // clear notification after click
Intent intent = new Intent(this, CheckInListPage.class);
PendingIntent pi = PendingIntent.getActivity(this,0,intent,Intent.FLAG_ACTIVITY_NEW_TASK);
mBuilder.setContentIntent(pi);
NotificationManager mNotificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
}
private int getNotificationIcon() {
boolean useWhiteIcon = (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP);
return useWhiteIcon ? R.drawable.logo_a_transparent : R.drawable.logo_notifc;
}
但在這裏我的問題是,當應用程序在前臺和可見運行時,它將把我logo_a_transparent並會得到期望的結果(截圖 - 在通知欄第一個圖標)。當通知圖標變成白色(屏幕截圖 - 通知欄中的第二個圖標)時,它會將我的應用程序圖標(android:icon =「@ drawable/ic_launcher」)作爲暫停應用程序並進行FCM推送。
將應用程序圖標替換爲透明將起作用,但不是正確的解決方案。
因爲您正在使用GetNotification()insteam使用getData()方法每次調用onmessageReceived,並且您可以使用相同的圖標 –
請參閱此處:http://stackoverflow.com/questions/28387602/notification-bar-icon-turns -white-in-android-5-lollipop –
我已經這樣做了......但是當我們暫停應用程序並且FCM推送到來時,通知圖標變爲白色(屏幕截圖 - 通知欄中的第二個圖標)。當應用程序前臺時,沒有問題。 –