Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Loops 如何使用Kotlin将mutableList循环到Android通知中的多行?_Loops_Kotlin_Notifications_Android Notifications_Mutablelist - Fatal编程技术网

Loops 如何使用Kotlin将mutableList循环到Android通知中的多行?

Loops 如何使用Kotlin将mutableList循环到Android通知中的多行?,loops,kotlin,notifications,android-notifications,mutablelist,Loops,Kotlin,Notifications,Android Notifications,Mutablelist,我试过\n,但它仍然有效,但不起作用。下面是我的代码: val channelId = resources.getString("NotificationChannelID") createNotificationChannel("NotifactionChannelName", channelId) val pendingIntent: PendingIntent = Intent(this, MainActivity::class.java).let { notifica

我试过
\n
,但它仍然有效,但不起作用。下面是我的代码:

val channelId = resources.getString("NotificationChannelID")

createNotificationChannel("NotifactionChannelName", channelId)

val pendingIntent: PendingIntent =
        Intent(this, MainActivity::class.java).let { notificationIntent ->
               PendingIntent.getActivity(this, 0, notificationIntent, 0)
        }
        val notification = Notification.Builder(this, channelId)
                .setContentText("First Line \n Second Line \n")
                .setSmallIcon(R.drawable.notification_icon)
                .setContentIntent(pendingIntent)
                .build()

        startForeground(NOTIFICATION_MANAGER_NOTIFICATION_ID, notification)



       for(e in error.iterator())
       {
                Log.d("Errors: ", "$e")
       }
您可以使用“NotificationCompat.InboxStyle” 以下是谷歌手册中的片段

var notification = NotificationCompat.Builder(context, CHANNEL_ID)
    .setSmallIcon(R.drawable.new_mail)
    .setContentTitle("5 New mails from " + sender.toString())
    .setContentText(subject)
    .setLargeIcon(aBitmap)
    .setStyle(NotificationCompat.InboxStyle()
            .addLine(messageSnippet1)
            .addLine(messageSnippet2))
    .build()
您可以迭代列表,并使用addLine将其添加到消息堆栈中


更多信息,请看一下。

非常感谢,我必须解决这个问题