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

我目前正在研究 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性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...