Android通知未显示超过3个操作

时间:2017-03-01 14:21:17

标签: android notifications android-notifications

我想显示一个包含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);

2 个答案:

答案 0 :(得分:7)

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

  

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

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

参考

Read Custom Notification Layouts

Adding button action in custom notification

答案 1 :(得分:1)

通知只能显示3个动作。

  

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

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

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