添加操作在软糖通知忽略了自定义布局与setContent设置 [英] Adding actions to a notification in jellybean ignores the custom layout set with setContent

查看:266
本文介绍了添加操作在软糖通知忽略了自定义布局与setContent设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建使用setContent自定义布局的通知,并能正常工作。
但是,当我加入行动,与的addAction()通知,我的自定义布局被忽略,它显示了Android的默认通知布局。

I'm creating a notification with a custom layout using setContent, and it works fine. But when I'm adding actions to the notification with addAction(), my custom layout is being ignored and it shows up the android's default notification layout.

当我缩小通知(使用两个手指的手势)我的自定义布局显示,如此看来的扩展的形式使用不同的布局,我无法设置。

When I shrink the notification (using the two fingers gesture) my custom layout shows, so it seems the "expanded" form uses a different layout which I cannot set.

截图(有了动作,然后滑动手指可缩小之后再)

Screenshots (With the actions, and then after swiping two fingers up to shrink it)

正如你所看到的,它显示了空(=默认布局)时显示的动作。

As you can see, it shows up empty (=default layout) when the actions are shown.

在code:

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;

我想找个地方控制的通知与 - 行动的布局,没有运气。任何帮助吗?

I tried to find somewhere to control the notification-with-actions layout, with no luck. Any help?

推荐答案

要是完全一样的问题!而不是调用的

Had exactly the same issue! Instead of calling

builder.setContent(remoteView)

它取代了正常的内容,你应该这样做是这样的:

Which replaces the normal content, you should do it like this:

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

这将您的布局设置为bigContentView,从而扩大后变为可见!

Which will set your layout to the bigContentView, which becomes visible after expanding!

请注意:这样做将prevent从显示出来的操作按钮。见<一href=\"http://stackoverflow.com/questions/12247153/in-android-on-jb-how-can-i-add-an-action-to-a-custom-rich-notification\">In机器人(上JB),我怎么可以添加到自定义丰富的通知的动作?如何来解决这个问题。

NOTE: Doing this will prevent your action buttons from showing up. See In Android (on JB), how can I add an action to a custom rich notification? for how to get around this

这篇关于添加操作在软糖通知忽略了自定义布局与setContent设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆