Currently, I had implemented multi-line notification
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this.getApplicationContext())
.setContentIntent(contentIntent)
.setSmallIcon(R.drawable.ic_notification)
.setContentTitle(contentTitle)
.setDefaults(Notification.DEFAULT_SOUND)
.setTicker(ticker)
.setContentText(contentText);
// Need BIG view?
if (size > 1) {
NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
// Sets a title for the Inbox style big view
inboxStyle.setBigContentTitle(contentTitle);
for (String notificationMessage : notificationMessages) {
inboxStyle.addLine(notificationMessage);
}
mBuilder.setStyle(inboxStyle);
}
NotificationManager mNotificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
However, this is not exactly what I want. When I look at GMail implementation, I realize their left hand side text (Yan Cheng Cheok) of every line, is being highlighted.
I was wondering, what is the technique to achieve such effect? As I would like to highlight my stock names.
the code inboxStyle.addLine(notificationMessage);
accepts a CharSequence
as the parameter, not a String
so you can easily achieve the effect you want by applying UnderlineSpan
follows reference links:
https://developer.android.com/reference/android/text/style/UnderlineSpan.html
How to set underline text on textview?
quick edit:
I just realise the OP mention highlight
and not underline
but the answer is still the same,there're several types of CharacterSpan the OP can choose to customise the text:
https://developer.android.com/reference/android/text/style/CharacterStyle.html
You have a few options to make some text bold.
The first option is to use Html.fromHtml(String)
and put a bold tag in your text like so:
for (String notificationMessage : notificationMessages) {
CharSequence content = Html.fromHTML("<b>This is bold</b> and this is not");
inboxStyle.addLine(content);
}
If you don't want to use HTML, you can also use a Span to accomplish the same thing:
Spannable sb = new SpannableString("Bold text");
sb.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), 0, sb.length() - 1,
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
inboxStyle.addLine(sb);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With