Android notification - custom inboxstyle (add line )

旧街凉风 提交于 2019-12-11 11:53:51

问题


I'd like to create a create expandable notification, in the pretty much gmail-like style. In general, using NotificationCompat.InboxStyle would be enough. But i need to add an icon in each line. Pretty much like Whatsapp do. See the screenshot Any ideas how to implement it? Besides custom layout with RemoteViews


回答1:


Quickly wrote some poor code and I have emojis everywhere.

String emoji = new String(Character.toChars(0x1F60A));
Notification noti = new Notification.Builder(this)
            .setContentTitle("5 New mails from " + emoji)
            .setContentText(emoji)
            .setSmallIcon(R.mipmap.ic_launcher)
            .setStyle(new Notification.InboxStyle()
                    .setBigContentTitle(emoji)
                    .addLine(emoji)
                    .addLine(emoji)
                    .setSummaryText(emoji))
            .build();

NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(1, noti);


来源:https://stackoverflow.com/questions/38609148/android-notification-custom-inboxstyle-add-line

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!