如何使用Kotlin在Android通知中循环mutableList到多行?[重复]

问题描述 投票:0回答:1

我试过了 \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")
       }
loops kotlin notifications android-notifications mutablelist
1个回答
1
投票

你可以使用 "NotificationCompat.InboxStyle "这里是google手册的片段。

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来添加到消息堆栈中。

更多的内容请看这里 联系.

© www.soinside.com 2019 - 2024. All rights reserved.