

我的代码如下。通知显示在第一张图片中。当我向下拖动打开通知栏时,就像第二个一样。我想知道为什么会有一个显示得很好的大图标和右下角,还有一个白色的空白图标…
我该怎么纠正它呢?代码如下所示。
builder = new NotificationCompat.Builder(context);
mRemoteViews = new RemoteViews(context.getPackageName(), R.layout.notify);
final Intent intent = new Intent(context, MainActivity.class);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Bitmap largeIcon = BitmapFactory.decodeResource(context.getResources(), R.drawable.icon);
builder.setAutoCancel(false);
builder.setSmallIcon(R.drawable.icon);
builder.setLargeIcon(largeIcon);
builder.setContentTitle(context.getString(R.string.app_name));
builder.setOngoing(true);发布于 2018-09-14 12:37:24
我希望这对你有用。
Notification notification = new Notification.Builder(getApplicationContext())
.setContentTitle(getString(R.string.app_name))
.setContentText("Your Content Text")
.setSmallIcon(getNotificationIcon())
.setWhen(System.currentTimeMillis())
.setContentIntent(contentIntent)
.setAutoCancel(true)
.build();
private int getNotificationIcon() {
boolean useWhiteIcon = (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP);
return useWhiteIcon ? R.drawable.app_icon_trans : R.drawable.app_icon;
}并确保您的图像背景应该是transparent.Version棒棒糖和以上的通知所需的透明背景图像。
发布于 2018-09-14 12:47:07
您用于通知的镜像无效/ android不支持。我认为你的问题是通知图标可能是多色的。理想情况下,图标应该是单色的。android状态栏只显示两种色调的图标,白色+彩色。你可以找到更多信息here
https://stackoverflow.com/questions/52324916
复制相似问题