回答

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