Android 设置自定义通知-显示全文
示例
如果要在上下文中显示长文本,则需要设置自定义内容。
例如,您有:
但您希望您的文字能完整显示:
您需要做的就是向您的内容添加样式,如下所示:
private void generateNotification(Context context) {
String message = "This is a custom notification with a very very very very very very very very very very long text";
Bitmap largeIcon = BitmapFactory.decodeResource(getResources(), android.R.drawable.ic_dialog_alert);
NotificationCompat.Builderbuilder = new NotificationCompat.Builder(context);
builder.setContentTitle("Title").setContentText(message)
.setSmallIcon(android.R.drawable.ic_dialog_alert)
.setLargeIcon(largeIcon)
.setAutoCancel(true)
.setWhen(System.currentTimeMillis())
.setStyle(new NotificationCompat.BigTextStyle().bigText(message));
Notification notification = builder.build();
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
notificationManager.notify(101, notification);
}
热门推荐
10 儿子立冬祝福语简短独特
11 对当兵的祝福语简短
12 侄儿高考试祝福语简短
13 伴郎红包祝福语朋友简短
14 媳妇生日简短祝福语朋友
15 公司年会祝福语简短最好
16 元旦感恩祝福语简短大全
17 红包祝福语简短10字
18 周六早晨祝福语简短