2

In my project, need change heads-up notification layout.

I have custom two remoteView, one for Notification.contentView, one for Notification.bigContentView and its succeed.

When I want to use Notification.Builder.addAction to add click button, it will use system layout not mine.

I changed another way, I custom layout & click button in my own layout, but it only show 64dp height.

    Notification.Builder nb = new Notification.Builder(NotificationDemo.this);
PendingIntent pi = PendingIntent.getActivity(NotificationDemo.this, 1, new Intent(NotificationDemo.this, MainActivity.class), Intent.FLAG_ACTIVITY_NEW_TASK);
nb.setFullScreenIntent(pi, true);
nb.setSmallIcon(R.drawable.notification_icon);

//nb.addAction(R.drawable.ic_delete, getResources().getString(R.string.app_name), pi);
RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.notification_demo);
RemoteViews bigcontentView = new RemoteViews(getPackageName(), R.layout.notification_demo_bigg);
Notification mNo = nb.build();
mNo.bigContentView = bigcontentView;
mNo.contentView = contentView;
nm.notify(10000, mNo);

Second way:

Notification.Builder nb = new Notification.Builder(NotificationDemo.this);
PendingIntent pi = PendingIntent.getActivity(NotificationDemo.this, 1, new Intent(NotificationDemo.this, MainActivity.class), Intent.FLAG_ACTIVITY_NEW_TASK);
nb.setFullScreenIntent(pi, true);
nb.setSmallIcon(R.drawable.notification_icon);

nb.addAction(R.drawable.ic_delete, getResources().getString(R.string.app_name), pi);
RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.notification_demo);
RemoteViews bigcontentView = new RemoteViews(getPackageName(), R.layout.notification_demo_bigg);
Notification mNo = nb.build();
mNo.bigContentView = bigcontentView;
mNo.contentView = contentView;
nm.notify(10000, mNo);

Third way, I add actionbutton in layout.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Steve
  • 61
  • 1
  • 9

1 Answers1

3

In lollipop the notification has a new field named headsupContentView. use your custom remoteview, set to headsupContentView. it can be change.

Steve
  • 61
  • 1
  • 9