我试图在 .setContentText() 中发出一个带有换行符的通知,但这不起作用。
我的通知的构建者
builder.setContentTitle("Notification")
.setSmallIcon(R.drawable.notif)
.setContentText("Example1 "+"\n"+" Example2")
.setDefaults(Notification.DEFAULT_ALL)
.setAutoCancel(true)
.setContentIntent(contentIntent)
.setTicker("testing it")
.setVibrate(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400})
.setPriority(Notification.PRIORITY_HIGH);
在通知中:Example1 Example2
但我需要
Example1
Example2
最佳答案
据我所知,setContentText()
中的换行符被忽略,因为它被压缩了。你可以试试BigTextStyle
,例如:
builder.setContentTitle("Notification")
.setSmallIcon(R.drawable.notif)
.setStyle(new NotificationCompat.BigTextStyle()
.bigText("Example1\nExample2")
)
.setDefaults(Notification.DEFAULT_ALL)
.setAutoCancel(true)
.setContentIntent(contentIntent)
.setTicker("testing it")
.setVibrate(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400})
.setPriority(Notification.PRIORITY_HIGH);
参见:https://developer.android.com/reference/android/app/Notification.BigTextStyle获取更多信息。
关于android - 换行符在 Notifications android studio 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51143105/