android 多条通知,具有较长文本的Android多行通知/通知

对于Jelly Bean及更高版本,您可以使用可扩展通知。 最简单的方法是使用NotificationCompat.BigTextStyle进行通知。

像这样:

NotificationCompat.BigTextStyle bigTextStyle = new NotificationCompat.BigTextStyle(); bigTextStyle.setBigContentTitle(getString(R.string.title)); bigTextStyle.bigText(getString(R.string.long_explanation)); mBuilder.setStyle(bigTextStyle);

NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_notification) .setContentTitle(title) .setStyle(new NotificationCompat.BigTextStyle() .bigText(message)) .setContentText(message) .setDefaults(NotificationCompat.DEFAULT_SOUND) .setContentIntent(contentIntent) .setAutoCancel(true); mNotificationManager.notify(requestID, mBuilder.build());

曾经有人试过https://developer.android.com/guide/topics/ui/notifiers/notifications.html

通知视图的高度限制为65sp 。 这是实现细节,没有记录, 并且已在Android 4.1中进行了更改以支持可扩展通知 。 所以不要依赖于这个特定的值,而是依赖于视图的高度有限的事实。

以下是status_bar_latest_event.xml ,用于在通知区域中status_bar_latest_event.xml视图:

这对我来说在5.0上有用。它很好地包裹了长线。 它还允许您提供一系列字符串,这些字符串将以新行分隔显示。

String[] multilineDescription = new String[] { "line 1", "another very long line that will get wrapped." }; NotificationCompat.Builder builder = new NotificationCompat.Builder(appContext) .setSmallIcon(smallIcon) .setContentTitle(title) .setContentText("Pull down for more information"); String description; if (null == multilineDescription || multilineDescription.length == 0) { description = "No more information."; } else { description = multilineDescription[0]; for (int i=1; i

我的理解是Android的通知系统每个通知的高度有限,以避免单个通知填满屏幕。

从您链接的页面:

警告:使用自定义通知布局时,请特别注意确保自定义布局使用不同的设备方向和分辨率。 虽然此建议适用于所有View布局,但对于通知尤为重要,因为通知抽屉中的空间非常有限 。 不要使自定义布局过于复杂,并确保以各种配置进行测试。

但是,您可以在通知中显示多个通知,“粘性”通知或可能滚动文本。

有关通知可以执行的操作的详细信息,请参阅:

通知和通知生成器

Android提供了一个大视图可扩展通知,他们支持3种风格,bigpicture风格,收件箱风格,大文本风格(256 dp),但只有Android版本大于果冻豆。 对于较低版本,我们没有任何大文本样式通知。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值