如何强制通知以多行显示文字?

时间:2015-08-04 04:44:30

标签: android notifications statusbar

我的状态栏通知消息太长,所以我想在多行上显示它,但我不知道为什么它没有显示那样。

这是我的代码:

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 ...

1 个答案:

答案 0 :(得分:1)

如果您想在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