【问题标题】:Android notification not showing more than 3 actionsAndroid 通知未显示超过 3 个操作
【发布时间】:2017-03-01 14:21:17
【问题描述】:

我想显示一个包含 5 个操作的通知,但它只显示其中的 3 个。这是我用来显示它的代码

Notification notification =
            new android.support.v7.app.NotificationCompat.Builder(this)
                    .setSmallIcon(R.drawable.ic_launcher)
                    .setContentTitle("My notification")
                    .setContentText("Hello World!")
                    .addAction(new NotificationCompat.Action.Builder(R.drawable.action1, null, pendingIntent1).build())
                    .addAction(new NotificationCompat.Action.Builder(R.drawable.action2, null, pendingIntent2).build())
                    .addAction(new NotificationCompat.Action.Builder(R.drawable.action3, null, pendingIntent3).build())
                    .addAction(new NotificationCompat.Action.Builder(R.drawable.action4, null, pendingIntent4).build())
                    .addAction(new NotificationCompat.Action.Builder(R.drawable.action5, null, pendingIntent5).build())
                    .setAutoCancel(false)
                    .build();

NotificationManager notificationManager =
                (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        notificationManager.notify(MEETING_NOTIFICATION_ID, notification);

【问题讨论】:

    标签: android notifications android-notifications


    【解决方案1】:

    您也只能显示Notification.Builder addAction (Notification.Action action) 中提到的最多 3 个操作

    展开形式的通知最多可以显示 3 个操作,从 按添加顺序从左到右。

    或者,您可以创建自定义 RemoteViews 并使用 setCustomContentView

    参考

    Read Custom Notification Layouts

    Adding button action in custom notification

    【讨论】:

      【解决方案2】:

      通知只能显示 3 个操作。

      展开形式的通知最多可以显示 3 个操作,从 按添加顺序从左到右。

      来源,官方 Notification.Builder 文档:https://developer.android.com/reference/android/app/Notification.Builder.html#addAction(android.app.Notification.Action)

      如果您绝对需要超过 3 个操作,则必须选择使用自定义视图显示在通知中的解决方案。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-12-16
        • 1970-01-01
        • 2013-04-09
        • 2023-03-10
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多