android - 自定义通知布局不适用于 Android 2.3 或更低版本

标签 android layout notifications

我使用 NotificationCompat.Builder 通过 android 版本显示我的通知,并为通知使用自定义布局。
自定义布局在 Android 3 及更高版本(API 级别 11)上运行良好,但在 API 级别 10 或更低版本上不显示。我在模拟器中对 2.3 和 2.2 进行了测试。

这是我的代码:

    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 及更低版本上不行。

最佳答案

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

您可能必须通过直接应用 contentView 来解决它:

not.contentView = contentView;

关于android - 自定义通知布局不适用于 Android 2.3 或更低版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12574386/

相关文章:

java - ProGuard 中类路径前的感叹号有什么作用?

android - 我如何在Android中制作动态翻转屏幕(如iPhone)

android - 是否有 Android 工具可以找到正在运行的应用程序的布局名称?

Android 支持带图像的多屏幕

当应用程序处于终止状态时,iOS 静默推送通知不会收到

android - 等待 Camera.PictureCallback

java - android中按钮点击事件出错

javascript - div 之间不需要的垂直间距

php - 可靠的站点错误通知系统?

android - Android 应用程序监听传入 TCP/IP 消息的最佳方式是什么?