android - 如何强制通知以多行显示文本?

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

最佳答案

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

相关文章:

java - Android Wear Intent 过滤器

android - Android 与 iPhone 中的广播接收器/服务

xcode - iOS 7 状态栏和 self.view.frame 和 self.view.bounds

Android:如何正确隐藏系统用户界面

android - Cordova "Local Notifications"插件?

delphi - 加快Delphi状态栏的更新速度

android - 如何从 ListView 中获取选定的值以显示在第二个 Activity 中?

java - 在Android编程中,如何在不使用XML的情况下用Java制作GridView?

android - 如何解决 Failed to convert @drawable/abc into a drawable?

ios - 本地通知未触发