通知正文多行

3

enter image description here

如何将其变成两行,像下面这样:

提示

待跟进:9

未处理咨询:11

我传递了一个字符串值"待跟进:" + 所有跟进 + "\n" + "未处理咨询:" + 未处理咨询数量但没有显示成两行。

我使用的是android:minSdkVersion="7"

2个回答

4
在你的代码中加入以下内容:
NotificationCompat.Builder builder = new NotificationCompat.Builder(
                context);
        Notification notification = builder.setContentIntent(contentIntent)
                .setSmallIcon(icon).setTicker(appname).setWhen(0)
                .setAutoCancel(true).setContentTitle(appname)
                .setStyle(new NotificationCompat.BigTextStyle().bigText(message))
                .setContentText(message).build();

        notificationManager.notify(0, notification);

希望这能帮到您:

也可以查看这个链接:通知扩展

祝您好运。


我正在使用API级别7。 - A J
Android 4.1支持可展开通知。除了普通的通知视图外,还可以定义一个大视图,在通知被展开时显示。有三种样式可用于大视图:大图片样式、大文本样式和收件箱样式。 - Siddharth_Vyas
我认为API7没有相关功能。 - Siddharth_Vyas
对于API 16(目前设备的95%),您可以使用https://developer.android.com/reference/android/app/Notification.BigTextStyle.html而不是NotificationCompat。 - pzulw
@Siddharth_Vyas 这里 setTicker(appname) 和 setWhen(0) 的作用是什么? - KJEjava48

1
你可以使用RemoteViews来实现这个功能。
在你的custom_notification.xml文件中。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/custom_notification"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:gravity="center" >

    <ImageView
        android:id="@+id/notifiation_image"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
     />

    <TextView 
         android:id="@+id/notification_title"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_toRightOf="@id/notification_image"
         android:layout_alignTop="@+id/notification_image"
     />

    <TextView
        android:id="@+id/notification_text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@+id/notification_image"
        android:layout_below="@+id/notification_title"
    />
    <TextView
        android:id="@+id/notification_text_second_line"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@+id/notification_image"
        android:layout_below="@+id/notification_text"
    />

</RelativeLayout>

在通知构建代码中:
RemoteViews contentView = new RemoteViews(getPackageName(),    R.layout.custom_notification);
contentView.setImageViewResource(R.id.notification_image,      R.drawable.notification_image);
contentView.setTextViewText(R.id.notification_title, "My custom    notification title");
contentView.setTextViewText(R.id.notification_text, "My custom notification text");
contentView.setTextViewText(R.id.notification_text_second_line, "My custom notification text second line");
NotificationCompat.Builder builder = new NotificationCompat.Builder(
            context);
Notification notification = builder
            .setAutoCancel(true)
            .setContent(contentView).build();
notificationManager.notify(0, notification);

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接