首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >自定义通知布局在Android 2.3或更低版本上不起作用

自定义通知布局在Android 2.3或更低版本上不起作用
EN

Stack Overflow用户
提问于 2012-09-25 07:35:31
回答 1查看 8.3K关注 0票数 18

我使用NotificationCompat.Builder通过android版本显示我的通知,并对通知使用自定义布局。

自定义布局在Android3和更高版本(API级别11)上运行良好,但在API级别10或更低级别上不显示。我在Emulator中的2.3和2.2上测试了它。

下面是我的代码:

代码语言:javascript
复制
    Builder builder = new NotificationCompat.Builder(getApplicationContext());

    RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.notification_layout);
    contentView.setImageViewResource(R.id.notImage, R.drawable.stat_icon);
    contentView.setTextViewText(R.id.notTitle, getResources().getString(R.string.streamPlaying));
    contentView.setTextViewText(R.id.notText, StartActivity.streamName + " " + getResources().getString(R.string.playing));

    builder
            .setContentTitle(getResources().getString(R.string.streamPlaying))
            .setContentText(StartActivity.streamName + " " + getResources().getString(R.string.playing))
            .setSmallIcon(R.drawable.stat_icon)
            .setContentIntent(pendingIntent)
            .setOngoing(true)
            .setWhen(0)
            .setTicker(StartActivity.streamName + " " + getResources().getString(R.string.playing))
            .setContent(contentView);

    not = builder.build();

非常基础。布局文件是正确的,它与android.com上的通知教程中的相同,以确保我没有在其中犯错误。;)

记住:在3.0和更高版本上可以正常工作,但在2.3和更低版本下就不行了。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-09-25 07:55:45

这可能是支持库中的错误-请参阅this issue

您可能需要通过直接应用contentView来解决此问题:

代码语言:javascript
复制
not.contentView = contentView;
票数 38
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12574386

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档