通知抽屉中显示的图标

时间:2014-10-24 13:01:50

标签: java android notifications icons builder

我想问一下,当没有向下滚动时,是否可以使用LargeIcon作为通知抽屉中显示的图标。

显式:

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());

我知道这个设置是NotificationBuilder的默认选项,但有没有办法避免这种行为? 如果我的问题不够明确,请不要犹豫提问。

提前致谢!

1 个答案:

答案 0 :(得分:0)

AFAIK没有办法将Bitmap用于小图标,但你可以做一个:

warningBuilder.setSmallIcon(R.drawable.alert_warnings_yellow);

如果您想在展开式布局中使用不同的小图标而不是在自动收报机样式通知中(当通知抽屉关闭时),那么您需要使用自定义布局进行通知:

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

有很多关于如何在SO上创建自己的通知布局的示例: https://stackoverflow.com/search?q=android+custom+notification+layout