【发布时间】:2016-02-02 10:15:09
【问题描述】:
我有这个构建通知的代码,我需要删除左上角屏幕上的小图标,我需要询问是否有任何方法可以防止在创建通知时显示此图标
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager notificationManager =
(NotificationManager) getSystemService(ns);
RemoteViews notificationView = new RemoteViews(getPackageName(),
R.layout.mynotification);
Notification.Builder notification = new Notification.Builder(
getApplicationContext())
.setTicker(tickerText)
.setSmallIcon(R.drawable.ic_launcher)// here how can i make it null or transparent
.setAutoCancel(true)
.setContentIntent(mContentIntent)
.setVibrate(mVibratePattern)
.setContent(notificationView);
//the intent that is started when the notification is clicked (works)
Intent notificationIntent = new Intent(this, MainActivity.class);
PendingIntent pendingNotificationIntent = PendingIntent.getActivity(this, 0,
notificationIntent, 0);
//this is the intent that is supposed to be called when the
//button is clicked
Intent switchIntent = new Intent(this, switchButtonListener.class);
PendingIntent pendingSwitchIntent = PendingIntent.getBroadcast(this, 0,
switchIntent, PendingIntent.FLAG_UPDATE_CURRENT);
notificationView.setOnClickPendingIntent(R.id.closeOnFlash,
pendingSwitchIntent);
notificationView.setOnClickPendingIntent(R.id.appName,
pendingSwitchIntent);
Notification not = notification.build();
not.flags=Notification.FLAG_ONGOING_EVENT;
notificationManager.notify(1, not);
我需要将通知留在状态栏上,但不显示左上角的小图标
【问题讨论】:
-
你试过删除 setSmallIcon(R.drawable.ic_launcher)
-
是的,然后整个通知被删除!
-
我已经在这里回答了,可能对其他人有帮助,谢谢。 stackoverflow.com/a/53795196/5923085
标签: android icons android-notifications