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将其添加到消息堆栈中
更多信息,请看一下。非常感谢,我必须解决这个问题