我已經在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