Android 向jellybean中的通知添加操作会忽略带有setContent的自定义布局集

Android 向jellybean中的通知添加操作会忽略带有setContent的自定义布局集,android,android-notifications,android-4.2-jelly-bean,Android,Android Notifications,Android 4.2 Jelly Bean,我正在使用setContent创建一个带有自定义布局的通知,它运行良好。 但是,当我使用addAction()向通知中添加操作时,我的自定义布局将被忽略,并显示android的默认通知布局 当我收缩通知(使用两个手指手势)时,我的自定义布局显示出来,因此“扩展”表单似乎使用了我无法设置的不同布局 屏幕截图(带有动作,然后向上滑动两个手指以缩小) 如您所见,当显示操作时,它显示为空(=默认布局) 守则: RemoteViews remoteView = new RemoteViews(cont

我正在使用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;

我试图找到一个地方来控制通知与行动布局,没有运气。有什么帮助吗?

也有同样的问题!而不是打电话

builder.setContent(remoteView)
它取代了普通内容,您应该这样做:

Notification statusNotification = builder.build();
statusNotification.bigContentView = remoteViews;
它会将您的布局设置为bigContentView,该视图在展开后可见

注意:这样做将阻止您的操作按钮显示。看看如何避开这个问题