使用android InboxStyle()快速提问,我可以使用彩色字符串吗?我尝试使用Spannable
之类的
NotificationCompat.InboxStyle style = new NotificationCompat.InboxStyle();
text = "sample";
Spannable spannable = new SpannableString(text);
spannable.setSpan(new ForegroundColorSpan(Color.GREEN), 0, text.length(), 0);
style.addLine(spannable);
但没有运气...... :(
我可以添加颜色吗?谢谢!
答案 0 :(得分:4)
在Spannable.SPAN_EXCLUSIVE_EXCLUSIVE
中更改setSpan中的标记 spannable.setSpan(new ForegroundColorSpan(Color.GREEN), 0, text.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
<强>更新强>
NotificationCompat.Builder builder = new NotificationCompat.Builder(
this).setSmallIcon(R.drawable.ic_launcher);
NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
inboxStyle.setBigContentTitle("title");
inboxStyle.setSummaryText("summarytext");
String lineFormatted = "test";
Spannable sb = new SpannableString(lineFormatted);
sb.setSpan(new ForegroundColorSpan(Color.RED), 0, lineFormatted.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
inboxStyle.addLine(sb);
builder.setStyle(inboxStyle);
builder.setNumber(1);
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(1, builder.build());