我已经在 JellyBean 中制作了一个自定义 RemoteView,如所述 here , 并将其设置为通知的 bigContentView。
notification.bigContentView = customNotifView;
我试图在展开后将自定义布局放置在标准 contentView 的下方;类似 this 的东西.
问题是自定义布局覆盖展开后的标准contentView。
有办法吗?
最佳答案
我通过为名为 layout_base_content_notification.xml
的 contentView 创建自定义布局解决了这个问题,这与 Android 为通知提供的(手工制作)布局完全相同。
RemoteViews collapsedViews = new RemoteViews(c.getPackageName(), R.layout.layout_base_content_notification);
Notification noti = builder.build();
noti.contentView = collapsedViews;
然后我将它包含在名为 layout_big_content_notification.xml
的 customLayout 中:
<include
android:layout_width="match_parent"
android:layout_height="wrap_content"
layout="@layout/layout_base_content_notification" />
并将其添加为 bigContentView:
RemoteViews expandedViews = new RemoteViews(c.getPackageName(), R.layout.layout_big_content_notification);
noti.bigContentView = expandedViews;
现在,在扩展之后,bigContentView 取代了 contentView,但是它们的 header 是一样的。
如果有更好的解决方案,请告诉我。
关于Android 的扩展通知 - 扩展后的标准 ContentView 和自定义 BigContentView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22194860/