3

在此处输入图像描述

如何在两行中制作这个

警报

待跟进:9

一次未参加的查询:11

我正在传递一个字符串值“待跟进:”+ all_follow_ups +“\n”+“未参加过一次查询:”+ noOfEnquiry但未显示在两行中。

我正在使用它android:minSdkVersion="7"

4

2 回答 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);

另请检查:通知扩大

希望这可以帮助。

于 2013-11-01T06:35:56.417 回答
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);
于 2016-04-12T17:47:56.127 回答