自定义通知布局中的android edittext?

时间:2016-06-09 05:25:29

标签: android android-layout material-design android-notifications android-notification-bar

我们的想法是在自定义通知布局中显示电话号码,如果电话号码正常,则用户接受电话号码,并使用该电话号码启动待处理的意图。否则,用户可以选择在同一通知上编辑电话号码,并在号码正确后接受。是否可以使用自定义通知布局执行此操作?哪些API版本支持此类通知?

enter image description here

1 个答案:

答案 0 :(得分:1)

@Karakuri是对的。但Android宣布推出新版Android N.Android N支持内联回复。

添加内联操作。

  1. 创建一个可以添加到通知操作的RemoteInput.Builder实例。该类的构造函数接受系统用作文本输入键的字符串。稍后,您的掌上电脑应用程序会使用该密钥来检索输入文本。
  2. // Key for the string that's delivered in the action's intent.
    private static final String KEY_TEXT_REPLY = "key_text_reply";
    String replyLabel = getResources().getString(R.string.reply_label);
    RemoteInput remoteInput = new RemoteInput.Builder(KEY_TEXT_REPLY)
            .setLabel(replyLabel)
            .build();
    
    1. 使用addRemoteInput()将RemoteInput对象附加到操作。
    2. // Create the reply action and add the remote input.
      Notification.Action action =
              new Notification.Action.Builder(R.drawable.ic_reply_icon,
                      getString(R.string.label), replyPendingIntent)
                      .addRemoteInput(remoteInput)
                      .build();
      
      1. 将操作应用于通知并发出通知。
      2. // Build the notification and add the action.
        Notification newMessageNotification =
                new Notification.Builder(mContext)
                        .setSmallIcon(R.drawable.ic_message)
                        .setContentTitle(getString(R.string.title))
                        .setContentText(getString(R.string.content))
                        .addAction(action))
                        .build();
        
        // Issue the notification.
        NotificationManager notificationManager =
                NotificationManager.from(mContext);
        notificationManager.notify(notificationId, newMessageNotification);
        

        从内联回复中检索用户输入,请访问官方文档: https://developer.android.com/preview/features/notification-updates.html

        向后兼容性:

          

        通知组和远程输入都是其中的一部分   自Android 5.0(API级别21)以来支持Android的Notification API   穿戴设备。如果您已使用这些API构建通知,   您必须采取的唯一操作是验证应用行为   对应于上述指南,并予以考虑   实现setRemoteInputHistory()。

             

        为了支持向后兼容性,相同的API是   可以使用支持库的NotificationCompat类,   允许您构建适用于早期Android的通知   版本。在手持设备和平板电脑上,用户只能看到摘要   通知,因此应用程序仍应具有收件箱样式或   整个信息的等效通知代表   小组的内容。由于Android Wear设备允许用户查看所有内容   甚至在较旧的平台级别上的子通知,您应该构建   儿童通知,无论API级别如何。