简体   繁体   中英

Displayed Icon in Notification Drawer

I'd like to ask if it's possible to use the LargeIcon as the displayed icon in the notification drawer when it's not scrolled down.

Explicit:

NotificationCompat.Builder warningBuilder = new NotificationCompat.Builder(this);
Bitmap appWarningIcon = BitmapFactory.decodeResource(getResources(),
    R.drawable.alert_warnings_yellow);
warningBuilder.setLargeIcon(appWarningIcon); // I want this Icon to be displayed in the disabled notification drawer
warningBuilder.setSmallIcon(R.drawable.ic_launcher); //but currently this one is displayed
warningBuilder.setContentTitle("Warning: ");
warningBuilder.setContentText(Html.fromHtml(getString(R.string.alert_warning_message)));
warningBuilder.setLights(Color.YELLOW, 500, 500);
warningBuilder.setVibrate(new long[] {
    100, 250, 100, 250, 100, 250
});
warningBuilder.setStyle(new NotificationCompat.BigTextStyle()
    .bigText(Html.fromHtml(getString(R.string.alert_warning_message))));
NotificationManager warningNotificationManager =
    (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
warningNotificationManager.notify(4, warningBuilder.build());

I know that this setup is the default option from the NotificationBuilder but is there a way to avoid this behaviour? If my question isn't explicit enough please don't hestitate in asking detailed questions.

Thanks in advance!

AFAIK there's no way to use a Bitmap for the small icon but you could just do a:

warningBuilder.setSmallIcon(R.drawable.alert_warnings_yellow);

If you want to use a different small icon in the expanded layout than in the ticker style notification (when the notification drawer is closed) then you'd need to use a custom layout for the notification:

http://developer.android.com/guide/topics/ui/notifiers/notifications.html#CustomNotification

There are plenty of examples on how to create your own notification layout on SO: https://stackoverflow.com/search?q=android+custom+notification+layout

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM