我的应用程序生成通知,但我为该通知设置的图标未显示。相反,我得到一个白色的广场。
我曾尝试调整图标的png(尺寸为720x720,66x66,44x44,22x22)。奇怪的是,当使用更小的尺寸时,白色方块更小。
我搜索了这个问题,以及生成通知的正确方式,并且从我读过的代码应该是正确的。可悲的是,事情并不像他们应该做的那样。
我的手机是Android 5.1.1的Nexus 5。问题也出现在模拟器上,Android 5.0.1版本的三星Galaxy S4以及Android 5.0.1版本的摩托罗拉Moto G(我都借用过,现在还没有)
通知代码如下,两个截图。如果您需要更多信息,请随时索取。
@SuppressLint("NewApi") private void sendNotification(String msg, String title, String link, Bundle bundle) {
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
Intent resultIntent = new Intent(getApplicationContext(), MainActivity.class);
resultIntent.putExtras(bundle);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
resultIntent, Intent.FLAG_ACTIVITY_NEW_TASK);
Notification notification;
Uri sound = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.notificationsound);
notification = new Notification.Builder(this)
.setSmallIcon(R.drawable.lg_logo)
.setContentTitle(title)
.setStyle(new Notification.BigTextStyle().bigText(msg))
.setAutoCancel(true)
.setContentText(msg)
.setContentIntent(contentIntent)
.setSound(sound)
.build();
notificationManager.notify(0, notification);
}
发布于 2018-04-20 17:06:55
原因:对于5.0“通知图标必须完全是白色的”。
如果我们通过将目标SDK设置为20来解决白色图标问题,我们的应用将不会针对Android棒棒糖,这意味着我们不能使用棒棒糖特有的功能。
目标Sdk 21的解决方案
如果你想支持棒棒糖素材图标,然后为棒棒糖和以上版本制作透明图标。请参阅以下内容:https: //design.google.com/icons/
请查看http://developer.android.com/design/style/iconography.html,我们将看到白色风格是如何在Android Lollipop中显示通知。
谷歌还建议我们使用会显示在白色通知图标后面的颜色。请参阅链接:https://developer.android.com/about/versions/android-5.0-changes.html
对于低于和高于Lollipop操作系统版本的通知生成器的实现将是:
Notification notification = new NotificationCompat.Builder(this);
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
notification.setSmallIcon(R.drawable.icon_transperent);
notification.setColor(getResources().getColor(R.color.notification_color););
} else {
notification.setSmallIcon(R.drawable.icon);
}
注意:setColor仅在棒棒糖中可用,并且仅影响图标的背景。
它会完全解决你的问题!
https://stackoverflow.com/questions/-100003951
复制相似问题