在我的项目中,需要更改抬头通知布局。
我自定义了两个remoteView
,一个用于Notification.contentView
,一个用于Notification.bigContentView
并且成功。
当我想使用Notification.Builder.addAction
添加点击按钮时,它将使用系统布局而不是我的。
我改变了另一种方式,我自定义布局&单击我自己布局中的按钮,但它只显示64dp高度。
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);
第二种方式:
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);
第三种方式,我在布局中添加了动作按钮。
答案 0 :(得分:2)
在棒棒糖中,通知有一个名为headupContentView的新字段。使用您的自定义远程视图,设置为headsupContentView。它可以改变。