我的状态栏通知消息太长了,想多行显示,不知道为什么不显示。
这是我的代码:
String msg = "text1 text2 text3 text4 text5";
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context);
mBuilder.setContentTitle(context.getResources().getString(R.string.time_to_brush_title));
mBuilder.setContentText(msg);
mBuilder.setTicker(context.getResources().getString(R.string.time_to_brush_title));
mBuilder.setSmallIcon(R.drawable.ic_launcher);
mBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(msg));
但是,这是通知栏包含的内容:
text1 text2 text3 ...
最佳答案
如果你想在4.1中使用这种通知>那么使用
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.notification_icon)
.setContentTitle("Event tracker")
.setContentText("Events received")
NotificationCompat.InboxStyle inboxStyle =
new NotificationCompat.InboxStyle();
String[] events = new String[6];
// Sets a title for the Inbox in expanded layout
inboxStyle.setBigContentTitle("Event tracker details:");
...
// Moves events into the expanded layout
for (int i=0; i < events.length; i++) {
inboxStyle.addLine(events[i]);
}
// Moves the expanded layout object into the notification object.
mBuilder.setStyle(inBoxStyle);
这是引用链接 https://developer.android.com/guide/topics/ui/notifiers/notifications.html
关于android - 如何强制通知以多行显示文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31800862/