gpt4 book ai didi

android - 如何自定义单挑通知布局?

转载 作者:行者123 更新时间:2023-11-29 20:46:45 30 4
gpt4 key购买 nike

在我的项目中,需要更改提示通知布局。

我自定义了两个 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);

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

最佳答案

在 lollipop 中,通知有一个名为 headsupContentView 的新字段。使用您的自定义远程 View ,设置为 headsupContentView。它可以改变。

关于android - 如何自定义单挑通知布局?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30167444/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com