我知道,为了支持Lollipop材料设计指导方针,我们必须使通知图标透明。
下面是我的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并将得到所需的结果(通知栏中的屏幕截图第一图标)。
在您的menifestfile中添加这一行设置您的资源为您的选择添加这一行
<meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="@mipmap/ic_notification" />
<meta-data
android:name="com.google.firebase.messaging.default_notification_color"
android:resource="@android:color/transparent" />
我有一个显示自定义通知的应用程序。问题是在Android5运行时,通知栏中的小图标显示为白色。我该怎么解决这个?
我今天的通知图标有一个奇怪的问题。 我做了什么坏事吗? 这是我的图标图片(刚从这里下载https://material.io/icons/#ic_photo) : http://image.noelshack.com/fichiers/2016/44/1478185219-icon-notification.png 我错过什么了吗? 作为记录,我使用的是SDK 24,目前只创建了hdpi资源文件夹
由于通知图标没有一个单独的图像,我有点不知道如何做到这一点。 谢谢
我目前在Android Oreo在状态栏和通知本身上正确显示通知图标(下面提供的截图)时遇到了问题。 要创建图标,我使用Android3.1,右键点击res文件夹并选择New>Image Asset。在其中,我上传了一个全白的png(根据文档),并根据屏幕截图选择了一个红色背景: 在AndroidManifest.xml中,我设置了如下图标:
我如何在运行Android5.0的手机中自定义状态栏上的通知图标。它总是作为一个白色的盒子(图片附上)。
在Android5上,我的通知栏上的应用图标变为白色。我在Android5Lollipop上看到这个通知栏图标变为白色,但我如何在我的codenameone应用上更改它。