[英]How to make custom notification view with jetpack compose?
我想制作一个自定义通知视图,内容会按时间间隔更新。 自定义视图可能包含操作按钮。 在 android 文档中,我们可以使用 XML 布局文档创建自定义视图: https://developer.android.com/training/notify-user/custom-notification
// Get the layouts to use in the custom notification
val notificationLayout = RemoteViews(packageName, R.layout.notification_small)
val notificationLayoutExpanded = RemoteViews(packageName, R.layout.notification_large)
// Apply the layouts to the notification
val customNotification = NotificationCompat.Builder(context, CHANNEL_ID)
.setSmallIcon(R.drawable.notification_icon)
.setStyle(NotificationCompat.DecoratedCustomViewStyle())
.setCustomContentView(notificationLayout)
.setCustomBigContentView(notificationLayoutExpanded)
.build()
那么我们可以使用 Jetpack Compose 制作我们自己的自定义通知视图吗?
截至目前,我们不能在自定义远程视图布局文件中使用androidx.compose.ui.platform.ComposeView
。 目前,也没有其他选择
我们实现自定义通知的唯一方法是通过远程视图,但目前,远程视图不支持 ComposeView ......即使它支持也不值得,因为它不支持所有 API 级别
有关更多信息,请参阅远程视图中支持的小部件/视图
https://developer.android.com/reference/android/widget/RemoteViews
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.