android – 为什么果冻豆不会在通知中显示第二行?

android – 为什么果冻豆不会在通知中显示第二行?,第1张

概述我目前正在研究 Android Support Package v4 Rev 10的NotificationCompat功能. documentation表示’setContentText()’显示通知中的第二行.这适用于API 8直到API 15.但是,如果我尝试在API 16中使用此方法,我的通知将错过第二行.我只看到标题而不是第二行.添加多行是没有问题的(使用’addline()’). 这是 我目前正在研究 Android Support Package v4 Rev 10的NotificationCompat功能. documentation表示’setContentText()’显示通知中的第二行.这适用于API 8直到API 15.但是,如果我尝试在API 16中使用此方法,我的通知将错过第二行.我只看到标题而不是第二行.添加多行是没有问题的(使用’addline()’).

这是我使用的NotificationCompat.Builder的代码:

private NotificationCompat.Builder buildnormal(CharSequence pTitle) {    NotificationCompat.Builder builder = new NotificationCompat.Builder(            getSherlockActivity());    builder.setautoCancel(true).setDefaults(Notification.DEFAulT_ALL);    // set the shown date    builder.setWhen(System.currentTimeMillis());    // the Title of the notification    builder.setContentTitle(pTitle);    // set the text for pre API 16 devices    builder.setContentText(pTitle);    // set the action for clicking the notification    builder.setContentIntent(buildPendingIntent(Settings.ACTION_Security_SETTINGS));    // set the notifications icon    builder.setSmallicon(androID.R.drawable.stat_sys_download_done);    // set the small ticker text which runs in the tray for a few seconds    builder.setTicker("This is your ticker text.");    // set the priority for API 16 devices    builder.setPriority(Notification.PRIORITY_DEFAulT);    return builder;}

如果我想添加多行并显示通知,我使用此代码:

NotificationCompat.Builder normal = buildnormal("This is an Expanded Layout Notification.");    NotificationCompat.InBoxStyle big = new NotificationCompat.InBoxStyle(            normal);    // summary is below the action    big.setSummaryText("this is the summary text");    // lines are above the action and below the Title    big.addline("This is the first line").addline("The second line")            .addline("The third line").addline("The fourth line");    notificationmanager manager = getnotificationmanager(normal);    manager.notify(Constants.NOTIFY_ID,big.build());

这是Jelly Bean的想要功能,setContentText被忽略还是我错过了什么?代码在没有错误的所有版本上运行,但我想添加第二行,使用与ICS或更早版本相同的代码.

我还添加了两个截图.第一个来自我的ICS 4.0.3华为MediaPad,第二个来自galaxy Nexus和4.1.1.从1开始的第二行是简单的与通知标题相同的字符串.它在2不可见.

感谢您的帮助!

解决方法

Is this a wanted feature of Jelly Bean,that setContentText is ignored or am I missing something?

setContextText()的值应该在折叠状态下可见(例如,如果展开,则双指向上滑动,或者它不是最顶层的通知).在给定上面的代码的情况下,它将在展开状态下由NotificationCompat.InBoxStyle替换.

总结

以上是内存溢出为你收集整理的android – 为什么果冻豆不会在通知中显示第二行?全部内容,希望文章能够帮你解决android – 为什么果冻豆不会在通知中显示第二行?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://www.outofmemory.cn/web/1138483.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-30
下一篇 2022-05-30

发表评论

登录后才能评论

评论列表(0条)

保存