回答

0

您需要创建自己的RemoteViews,然后指出您希望展开的内容继承您的自定义RemoteViews

RemoteViews expandedView = new RemoteViews(YOUR CONTEXT.getPackageName(), YOUR CUSTOM LAYOUT); 
Notification notification = mBuilder.build(); 
notification.bigContentView = expandedView; 

或查看link.

+0

谢谢@Harshit,但本教程没有提供任何自定义bigContentView的示例。我真的需要这样做,因为没有任何默认样式符合我的要求。 – wverdese

+0

检查编辑答案。 –

+0

这正是我正在做的事情(实际上你提供的链接与我提出的问题相同)。问题是expandedViews **取代了通知的默认contentView,而我想**在扩展后追加** ...我的意思是,我需要在屏幕上同时显示contentView和bigContentView同时。 – wverdese

4

我通过创建内容查看自定义布局解决所谓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,但它们的头部是相同的。

请让我知道是否有更好的解决方案。

+0

“c”代表什么?来自c.getPackageName() – TeodorKolev

+0

上下文:https://developer.android.com/reference/android/content/Context.html#getPackageName() – wverdese