我已经在JellyBean中制作了一个定制的RemoteView,如here所述,并将其设置为通知的bigContentView。Android的扩展通知 - 扩展后的标准ContentView和自定义BigContentView
notification.bigContentView = customNotifView;
我想有自定义布局放置下面标准内容查看后扩大;例如this。
问题是自定义布局覆盖扩展后的标准contentView。
有没有办法做到这一点?
我已经在JellyBean中制作了一个定制的RemoteView,如here所述,并将其设置为通知的bigContentView。Android的扩展通知 - 扩展后的标准ContentView和自定义BigContentView
notification.bigContentView = customNotifView;
我想有自定义布局放置下面标准内容查看后扩大;例如this。
问题是自定义布局覆盖扩展后的标准contentView。
有没有办法做到这一点?
您需要创建自己的RemoteViews
,然后指出您希望展开的内容继承您的自定义RemoteViews
。
RemoteViews expandedView = new RemoteViews(YOUR CONTEXT.getPackageName(), YOUR CUSTOM LAYOUT);
Notification notification = mBuilder.build();
notification.bigContentView = expandedView;
或查看link.
我通过创建内容查看自定义布局解决所谓layout_base_content_notification.xml
,这是完全一样的(手工制作)布局Android提供了通知。
RemoteViews collapsedViews = new RemoteViews(c.getPackageName(), R.layout.layout_base_content_notification);
Notification noti = builder.build();
noti.contentView = collapsedViews;
然后我在一个customLayout包括它,叫layout_big_content_notification.xml
:
<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,但它们的头部是相同的。
请让我知道是否有更好的解决方案。
“c”代表什么?来自c.getPackageName() – TeodorKolev
上下文:https://developer.android.com/reference/android/content/Context.html#getPackageName() – wverdese
谢谢@Harshit,但本教程没有提供任何自定义bigContentView的示例。我真的需要这样做,因为没有任何默认样式符合我的要求。 – wverdese
检查编辑答案。 –
这正是我正在做的事情(实际上你提供的链接与我提出的问题相同)。问题是expandedViews **取代了通知的默认contentView,而我想**在扩展后追加** ...我的意思是,我需要在屏幕上同时显示contentView和bigContentView同时。 – wverdese