我有一个显示大图的通知。
有没有办法从此视图中删除蜂窝和上方设备中的较小图标?
显然仍然保留顶部状态栏的小图标
NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
// Set required fields, including the small icon, the
// notification title, and text.
.setSmallIcon(R.drawable.ic_notify_status_new)
.setContentTitle(title)
.setContentText(text)
// All fields below this line are optional.
// Use a default priority (recognized on devices running Android
// 4.1 or later)
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
// Provide a large icon, shown with the notification in the
// notification drawer on devices running Android 3.0 or later.
.setLargeIcon(picture)
.setContentIntent(
PendingIntent.getActivity(
context,
0,
notiIntent,
PendingIntent.FLAG_UPDATE_CURRENT)
);
builder = getNotiSettings(builder);
notify(context, builder.build());
答案 0 :(得分:13)
在构建通知后添加此代码。
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
int smallIconViewId = getResources().getIdentifier("right_icon", "id", android.R.class.getPackage().getName());
if (smallIconViewId != 0) {
if (notif.contentIntent != null)
notif.contentView.setViewVisibility(smallIconViewId, View.INVISIBLE);
if (notif.headsUpContentView != null)
notif.headsUpContentView.setViewVisibility(smallIconViewId, View.INVISIBLE);
if (notif.bigContentView != null)
notif.bigContentView.setViewVisibility(smallIconViewId, View.INVISIBLE);
}
}
其中“notif”是您构建的通知,
答案 1 :(得分:1)
只有一种方法: 使用您的自定义布局
重复答案 2 :(得分:-1)
仅将setSmallIcon用于您的图标。如果没有指定第二个,它也将用于largeIcon(只要确保它足够大以适应两者)。
确保它在pre-lolipop,lolipop及以上看起来不错。例如,这里我只为pre-lolipop设备设置应用程序图标,其中lolipop及以上版本的smallIcon与smallIcon相同,sizeIcon与smallIcon相同。
int currentApiVersion = android.os.Build.VERSION.SDK_INT;
if (currentApiVersion >= Build.VERSION_CODES.LOLLIPOP) {
notificationBuilder
.setSmallIcon(smallIcon)
.setLargeIcon(appIconDrawable)
} else {
notificationBuilder.setSmallIcon(appIconDrawable);
}