dig*_*gin 2 string notifications android colors spannable
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);
Run Code Online (Sandbox Code Playgroud)
但没有运气... :(
我可以添加颜色吗?谢谢!
在 Spannable.SPAN_EXCLUSIVE_EXCLUSIVE 上更改 setSpan 中的标志
spannable.setSpan(new ForegroundColorSpan(Color.GREEN), 0, text.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
Run Code Online (Sandbox Code Playgroud)
更新
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());
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1059 次 |
| 最近记录: |