如何自定义平视通知的布局? [英] How to Custom Heads-up notification layout?

查看:79
本文介绍了如何自定义平视通知的布局?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的项目中,需要更改抬头通知布局.

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

我自定义了两个 remoteView ,一个用于 Notification.contentView ,一个用于 Notification.bigContentView 及其成功.

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

当我想使用 Notification.Builder.addAction 添加单击按钮时,它将使用系统布局而不是我的.

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

我改变了另一种方式,我自定义布局&单击我自己的布局中的按钮,但它仅显示64dp高度.

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);

第二种方式:

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);

第三种方式,我在布局中添加了actionbutton.

Third way, I add actionbutton in layout.

推荐答案

在棒棒糖中,通知具有一个名为headsupContentView的新字段.使用您的自定义remoteview,将其设置为headsupContentView.可以改变.

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

这篇关于如何自定义平视通知的布局?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆