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

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

想法是在自定义通知布局中显示一个电话号码,如果电话号码正常,则用户接受该电话号码,并使用该电话号码启动挂起的 Intent 。否则,用户可以选择在同一通知上编辑电话号码,并在号码正确后接受。是否可以使用自定义通知布局来做到这一点?哪些 API 版本支持此类通知?

enter image description here

最佳答案

@Karakuri 是对的。但是 Android 宣布了新版本 Android N。Android N 支持内联回复。

添加内联 Action 。

  1. 创建一个 RemoteInput.Builder 实例,您可以将其添加到您的通知操作中。此类的构造函数接受系统用作文本输入键的字符串。稍后,您的手持应用程序会使用该 key 来检索输入的文本。
// 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 对象附加到操作。
// 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. 将操作应用于通知并发出通知。
// 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

向后兼容性:

Both notification groups and remote input have been a part of the Notification API since Android 5.0 (API level 21) to support Android Wear devices. If you've already built notifications with these APIs, the only action you must take is to verify that the app behavior corresponds to the guidelines described above, and to consider implementing setRemoteInputHistory().

In order to support backward compatibility, the same APIs are available with the support library's NotificationCompat class, allowing you to build notifications that works on earlier Android versions. On handhelds and tablets, users only see the summary notification, so an app should still have an inbox style or an equivalent notification representative for the whole information content of the group. As Android Wear devices allow users to see all child notifications even on older platform levels, you should build child notifications regardless of API level.

关于自定义通知布局中的android edittext?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37717471/

相关文章:

AppWidgetManager.updateAppWidget 中的 android.os.TransactionTooLargeException

java - Android 运行时错误,ActivityNotFoundException : No Activity

android-layout - 如何在 ICS 样式的 EditText 中更改线条的颜色

Android MaterialButton 不会在 android lollipop 中以编程方式更改它的颜色

android - 如何使用android.view.SurfaceView

android - 即使在实现 dats 消息后,FCM 推送通知也会显示原始 json

java - 安卓 "Cannot resolve symbol ' @id/myLabel"

angularjs - 增加工具提示字符限制 - MD-Angular Tooltip

css - 如何在避免 !important 的同时使用全局 styles.css 覆盖 Angular Material 样式?

android - 如何在 Android 上的 textview 或 imageview 上设置涟漪效果?