2012-10-13 17 views
4

我正在使用setContent創建具有自定義佈局的通知,並且它工作正常。 但是當我使用addAction()向通知添加動作時,我的自定義佈局被忽略,它顯示了Android的默認通知佈局。將動作添加到jellybean中的通知中將忽略使用setContent設置的自定義佈局

當我收縮通知(使用兩個手指手勢)時,我的自定義佈局顯示,所以看起來「展開」窗體使用了我不能設置的不同佈局。

截圖(有了動作,然後經過刷卡兩根手指可縮小它)

Expanded with actions

After shrinking it back

正如你所看到的,它顯示了空(=默認佈局)時顯示的行動。

代碼:

RemoteViews remoteView = new RemoteViews(context.getPackageName(), R.layout.notification_status); 
Builder builder = new Notification.Builder(context); 
builder.setSmallIcon(icon) 
    .setTicker(tickerText) 
    .setWhen(when) 
    .setContent(remoteView) 
    .setOngoing(true) 
    .setContentIntent(contentIntent) 
    .setPriority(Notification.PRIORITY_HIGH) 
    .addAction(R.drawable.ic_remove, "Action 1", cancelPendingIntent) 
    .addAction(R.drawable.ic_stat_notify_gray_official, "Action 2", cancelPendingIntent) 
    .setContentIntent(contentIntent); 
Notification statusNotification = builder.build(); 
return statusNotification; 

我想找個地方控制的通知與 - 行動的佈局,沒有運氣。任何幫助?

回答

1

有完全相同的問題!與其說

builder.setContent(remoteView) 

取代了正常的內容,你應該做的是這樣的:

Notification statusNotification = builder.build(); 
statusNotification.bigContentView = remoteViews; 

將設置您的佈局到bigContentView,其擴大後變得可見!

注意:這樣做會阻止您的操作按鈕顯示出來。如何解決此問題見In Android (on JB), how can I add an action to a custom rich notification?

相關問題