我正在尝试使用内联回复选项创建自定义通知布局。但是,回复操作未显示在通知中。不过,对于默认的通知视图,同样可以正常工作。
android.app.Notification.Builder notificationBuilder = new android.app.Notification.Builder(context, Constants.CHANNEL_ONE_ID)
.setSmallIcon(R.drawable.ic_notification)
.setLargeIcon(getBitmap(userId, getAvatarText(userId)))
.setSound(defaultSoundUri)
.setVibrate(pattern)
.setAutoCancel(true)
.setDeleteIntent(deleteIntent);
RemoteViews collapsedView = new RemoteViews(getPackageName(), R.layout.view_collapsed_notification);
String replyLabel = "Reply";
android.app.RemoteInput remoteInput = new android.app.RemoteInput.Builder(KEY_TEXT_REPLY)
.setLabel(replyLabel)
.build();
android.app.Notification.Action action = new android.app.Notification.Action.Builder
(Icon.createWithResource(WorkspaceApp.getInstance(), android.R.drawable.sym_action_chat), "Reply", pendingIntent)
.addRemoteInput(remoteInput)
.build();
notificationBuilder.setCustomContentView(collapsedView);
notificationBuilder.addAction(action);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
//notificationBuilder.addAction(action);
notificationManager.notify(notifId, notificationBuilder.build());
R.layout.view_collapsed_notification用于折叠视图。其中包含标题,内容和图像。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/margin_10"
android:orientation="horizontal">
<LinearLayout
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toStartOf="@+id/avatar"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:fontFamily="sans-serif-medium"
android:textSize="15dp"
android:textStyle="normal"
android:textColor="@android:color/black"
tools:text="Raksha User" />
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:textSize="14dp"
tools:text="Raksha User" />
</LinearLayout>
<ImageView
android:id="@+id/avatar"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_gravity="center_vertical"
android:layout_marginEnd="8dp"
android:src="@drawable/smiley_thumb" /> </LinearLayout></LinearLayout>
谢谢。