Android 10上的自定义通知中没有展开按钮

Android 10上的自定义通知中没有展开按钮,android,android-notifications,android-10.0,Android,Android Notifications,Android 10.0,我正在尝试用两个自定义视图构建可扩展的通知 在互联网上搜索说我需要使用这样的代码 val r = RemoteViews(activity.packageName, R.layout.cf_watcher_notification_small) val r2 = RemoteViews(activity.packageName, R.layout.cf_watcher_notification_big) val n = NotificationCompat.Builder(activity,

我正在尝试用两个自定义视图构建可扩展的通知

在互联网上搜索说我需要使用这样的代码

val r = RemoteViews(activity.packageName, R.layout.cf_watcher_notification_small)
val r2 = RemoteViews(activity.packageName, R.layout.cf_watcher_notification_big)

val n = NotificationCompat.Builder(activity, "test").apply {
    setSmallIcon(R.drawable.ic_develop)
    setNotificationSilent()
    setShowWhen(false)
    setAutoCancel(true)

    setCustomContentView(r)
    setCustomBigContentView(r2)
    setStyle(NotificationCompat.DecoratedCustomViewStyle())
}

但生成的通知并没有展开按钮,可以将折叠视图切换为大视图,反之亦然,当我按下通知按钮时,什么也不会发生

没有大内容视图的代码

    setCustomContentView(r)
    //setCustomBigContentView(r2)
    setStyle(NotificationCompat.DecoratedCustomViewStyle())
    //setCustomContentView(r)
    setCustomBigContentView(r2)
    setStyle(NotificationCompat.DecoratedCustomViewStyle())
预期的结果

只有大内容视图的代码

    setCustomContentView(r)
    //setCustomBigContentView(r2)
    setStyle(NotificationCompat.DecoratedCustomViewStyle())
    //setCustomContentView(r)
    setCustomBigContentView(r2)
    setStyle(NotificationCompat.DecoratedCustomViewStyle())
使用我需要的按钮将结果发送到通知


如何获取此按钮?

您必须使用
NotificationCompat.BigTextStyle
使其可扩展

范例-

 var notification = NotificationCompat.Builder(activity, "test")
    .setSmallIcon(R.drawable.ic_develop)
    .setNotificationSilent()
    .setShowWhen(false)
    .setAutoCancel(true)
    .setCustomContentView(r)
    .setCustomBigContentView(r2)
    .setStyle(NotificationCompat.BigTextStyle()
            .bigText(SOME_TEXT))
    .build()

您可以在

获取更多信息。您必须使用
NotificationCompat.BigTextStyle
使其可扩展

范例-

 var notification = NotificationCompat.Builder(activity, "test")
    .setSmallIcon(R.drawable.ic_develop)
    .setNotificationSilent()
    .setShowWhen(false)
    .setAutoCancel(true)
    .setCustomContentView(r)
    .setCustomBigContentView(r2)
    .setStyle(NotificationCompat.BigTextStyle()
            .bigText(SOME_TEXT))
    .build()

您可以在

BigTextStyle not provide获取更多信息,以根据需要设置自定义视图BigTextStyle not provide可根据需要设置自定义视图