【问题标题】:Adding actions to a notification in jellybean ignores the custom layout set with setContent在 jellybean 中向通知添加操作会忽略使用 setContent 设置的自定义布局
【发布时间】:2012-10-13 17:18:48
【问题描述】:

我正在使用 setContent 创建一个带有自定义布局的通知,它工作正常。 但是,当我使用 addAction() 向通知添加操作时,我的自定义布局被忽略了,它显示了 android 的默认通知布局。

当我缩小通知(使用两个手指手势)时,我的自定义布局会显示,因此“展开”表单似乎使用了我无法设置的不同布局。

截图(有动作,然后用两根手指向上滑动缩小)

如您所见,当显示操作时,它显示为空(=默认布局)。

代码:

RemoteViews remoteView = new RemoteViews(context.getPackageName(), R.layout.notification_status);
Builder builder = new Notification.Builder(context);
builder.setSmallIcon(icon)
    .setTicker(tickerText)
    .setWhen(when)
    .setContent(remoteView)
    .setOngoing(true)
    .setContentIntent(contentIntent)
    .setPriority(Notification.PRIORITY_HIGH)
    .addAction(R.drawable.ic_remove, "Action 1", cancelPendingIntent)
    .addAction(R.drawable.ic_stat_notify_gray_official, "Action 2", cancelPendingIntent)
    .setContentIntent(contentIntent);
Notification statusNotification = builder.build();
return statusNotification;

我试图找到某个地方来控制通知操作布局,但没有成功。有什么帮助吗?

【问题讨论】:

    标签: android android-notifications android-4.2-jelly-bean


    【解决方案1】:

    遇到了完全相同的问题!而不是调用

    builder.setContent(remoteView)
    

    替换正常内容,你应该这样做:

    Notification statusNotification = builder.build();
    statusNotification.bigContentView = remoteViews;
    

    这会将您的布局设置为 bigContentView,展开后变得可见!

    注意:这样做会阻止您的操作按钮出现。请参阅In Android (on JB), how can I add an action to a custom rich notification? 了解如何解决此问题

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-27
      • 2023-04-07
      • 2014-03-22
      • 2017-09-05
      • 1970-01-01
      相关资源
      最近更新 更多