我创建了一个包含标题,内容文本和进度条的通知
内容文本显示下载百分比。
问题是我的通知有时标题很长,这将导致内容文本被隐藏/不可见。
有没有一种方法可以使标题省略或强制显示内容文本?
我的生成器如下:
builder.setWhen(System.currentTimeMillis());
builder.setSmallIcon(android.R.drawable.stat_sys_download);
builder.setColor(ContextCompat.getColor(getBaseContext(), R.color.colorPrimary));
builder.setContentTitle(bookTitle);
builder.setContentText(getString(R.string.downloadservice_status_busy));
builder.setProgress(PROGRESS_MAX, 0, false);
builder.setPriority(Notification.PRIORITY_DEFAULT);
builder.setOnlyAlertOnce(true);
builder.setOngoing(true);
答案 0 :(得分:1)
您可以使用以下方式:
1。 NotificationCompat.Builder
有几种样式模式。
builder.setStyle(new NotificationCompat.BigTextStyle(builder)
.bigText(bigText)
.setBigContentTitle(bigContentTitleText)
.setSummaryText(summaryText)
)
builder.setStyle(new NotificationCompat.BigPictureStyle(builder)
.bigLargeIcon(your_bitmap_1)
.bigPicture(your_bitmap_2)
.setBigContentTitle(contentTitle)
.setSummaryText(summaryText)
)
builder.setStyle(new NotificationCompat.InboxStyle(builder)
.addLine(charsequence)
.setBigContentTitle(contentTitle)
.setSummaryText(summaryText)
)
2。。您可以为通知创建自定义layout.xml
:
RemoteViews layout = new RemoteViews(context.getPackageName(), R.layout.notification_layout);
//you can use different methods to customize your layout programmatically:
layout.setTextViewText(viewId, text); //set text to TextView
layout.setImageViewBitmap(R.id.imageviewID_in_your_layout, your_bitmap); //set bitmap to ImageView
layout.addView(...)
...
//Finally assign RemoteViews to the NotificationCompat.Builder:
NotificationCompat.Builder(context).setContent(layout).(...).build();