【问题标题】:How can I force a notification to display text in multiple lines?如何强制通知以多行显示文本?
【发布时间】:2015-10-26 08:40:04
【问题描述】:

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

这是我的代码:

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

【问题讨论】:

    标签: android notifications statusbar


    【解决方案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

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-09
    • 2013-04-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多