【问题标题】:Add icon button to the right side of the Notification在通知右侧添加图标按钮
【发布时间】:2018-04-26 19:01:05
【问题描述】:

我认为在 android 中显示动作的常用方式有点难以点击和被发现。用户需要执行两个操作(滑动通知,然后单击操作)。

所以我想在通知的右侧添加一个按钮,这样点击起来会更方便。


我发现的唯一方法是使用MediaStyle,但它有一些问题:

  1. 它会创建一个通知,但它全是黑色的

  1. 我不希望它像这样展开

  1. 我想添加常用操作(齿轮图标,配置屏幕的快捷方式)

到目前为止我得到的代码:

Notification notification = new NotificationCompat.Builder(this, CHANNEL_ID)
    .setSmallIcon(R.mipmap.ic_launcher_round)
    .setContentTitle("WorkTime")
    .setContentText("Estimativa de saída: 19:00h")
    .setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
    .setOngoing(true)
    .addAction(R.drawable.ic_fingerprint_black_24dp, "bater ponto", null)
    .setStyle(
        new android.support.v4.media.app.NotificationCompat.MediaStyle()
            .setShowActionsInCompactView(0)
    )
    .build();

notificationManager.notify(1, notification);

我需要implement a custom layout 来接收通知吗?

PS:您可能会注意到,smallIcon 不起作用。一些提示将不胜感激,但我知道那将是另一个问题,我想我可以自己找到解决方案。

【问题讨论】:

    标签: java android push-notification notifications kotlin


    【解决方案1】:

    你需要在通知上设置一个大图标

    【讨论】:

    • 我相信 largeIcon 仅适用于 Android N+。我的手机还是安卓M。另外,我觉得大图标不能有动作
    猜你喜欢
    • 1970-01-01
    • 2019-10-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多