简体   繁体   English

如何使用 Jetpack Compose 制作自定义通知视图?

[英]How to make custom notification view with 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在 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()

So can we make our own custom notification view using jetpack compose?那么我们可以使用 Jetpack Compose 制作我们自己的自定义通知视图吗?

As of now, we can't use androidx.compose.ui.platform.ComposeView in custom remote view layout file.截至目前,我们不能在自定义远程视图布局文件中使用androidx.compose.ui.platform.ComposeView And currently, there is no alternative to it also目前,也没有其他选择

The 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我们实现自定义通知的唯一方法是通过远程视图,但目前,远程视图不支持 ComposeView ......即使它支持也不值得,因为它不支持所有 API 级别

For more info here are the widgets/views supported in remote views有关更多信息,请参阅远程视图中支持的小部件/视图

https://developer.android.com/reference/android/widget/RemoteViews https://developer.android.com/reference/android/widget/RemoteViews

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM