Android 的扩展通知 - 扩展后的标准 ContentView 和自定义 BigContentView

标签 android notifications remoteview expandable android-4.2-jelly-bean

我已经在 J​​ellyBean 中制作了一个自定义 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/

相关文章:

android - 如何在 Android 模拟器上模拟硬件媒体控制按钮

ios - APNs 消息发送到服务器,设备 iOS 上没有通知

ios - WiFi 连接可用时通知

android - 设置 Android 小部件的初始滚动位置

android - App Widget 中的 LinearLayout

java - 带有 RemoteViews 的 Android 通知 - 具有与 RemoteViews 布局关联的 Activity

java - 通过参数从自定义ArrayList中删除重复项

java - 如何获取存储在 Android 设备外部存储中的 .apk 文件详细信息(如 : name, id、vercode ..等)

android - Kotlin 启动应用程序崩溃

iphone - iOS 如何告诉 App Delegate 从当前 View 呈现新 View