我的 Android 应用程序必须能够向一大群人发送简短的警报。显而易见的地方是在通知中心。完整的通知毫无问题地显示在代码中,但在通知中心,用户只能看到前几个单词,然后是省略号。通知一点也不长,最多只有10-15个字。如何让文本换行换行?
我构建通知的代码在这里
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.splash)
.setContentTitle("Student Engauge")
.setContentText(extras.getString("message"))
.setAutoCancel(true)
.setTicker(extras.getString("message"));
final int notificationId = 1;
NotificationManager nm = (NotificationManager) getApplicationContext()
.getSystemService(Context.NOTIFICATION_SERVICE);
nm.notify(notificationId, mBuilder.build());
最佳答案
要显示大量文本,请使用 BigTextStyle。这是 BigTextStyle 中给出的示例代码.此通知将包含一行文本,如果需要,将扩展到更多行。
Notification noti = new Notification.Builder()
.setContentTitle("New mail from " + sender.toString())
.setContentText(subject)
.setSmallIcon(R.drawable.new_mail)
.setLargeIcon(aBitmap)
.setStyle(new Notification.BigTextStyle()
.bigText(aVeryLongString))
.build();
对于安卓支持库
Notification noti = new Notification.Builder()
.setContentTitle("New mail from " + sender.toString())
.setContentText(subject)
.setSmallIcon(R.drawable.new_mail)
.setLargeIcon(aBitmap)
.setStyle(new NotificationCompat.BigTextStyle()
.bigText(aVeryLongString))
.build();
关于Android 通知 - 显示完整消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16470583/