如何使用 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 制作自己的自定义通知视图吗?
I wanted to make a custom notification view with content being updated in interval of time. The custom view might contain the action button. In android documentation, we can create custom view using XML layout docs: 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()
So can we make our own custom notification view using jetpack compose ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
截至目前,我们无法在自定义远程视图布局文件中使用
androidx.compose.ui.platform.ComposeView
。目前,也没有其他选择我们实现自定义通知的唯一方法是通过远程视图,但目前,远程视图不支持 ComposeView ...即使它支持它也不值得,因为它不支持所有 API 级别
有关详细信息,请参阅远程视图中支持的小部件/视图
https://developer.android.com/reference/android/widget/RemoteViews
As of now, we can't use
androidx.compose.ui.platform.ComposeView
in custom remote view layout file. And currently, there is no alternative to it alsoThe only way we achieve custom notification is via remote views but currently, remote view doesn't support ComposeView ... even if it supports it will not be worth since it wont support all API levels
For more info here are the widgets/views supported in remote views
https://developer.android.com/reference/android/widget/RemoteViews