可以使用Jetpack Compose来构建App窗口小部件吗? [英] Can Jetpack Compose be used to build App Widgets?

查看:133
本文介绍了可以使用Jetpack Compose来构建App窗口小部件吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

借助swift,可以使用SwiftUI编写小部件,但是我还没有看到关于Jetpack Compose是否可以用于构建Android App小部件的任何声明.

With swift, widgets can be written using SwiftUI, but I have not seen any statements regarding whether Jetpack Compose can be used to build Android App Widgets.

现在Compose在Alpha中,有没有信息可以让我看到如何完成?

Is there any information where I can see how that can be done now that Compose is in Alpha?

推荐答案

这在很大程度上取决于您所说的"Jetpack Compose"的含义.我们昨天才在 Kotlinlang Slack 上进行了讨论.

That depends a lot on what you mean by "Jetpack Compose". We were discussing this just yesterday on Kotlinlang Slack.

如果您指的是Compose UI和相关程序包(可用于构建活动显示的UI的可组合库),那么否,这对应用程序小部件的作用很小.从原则上讲,您可以将可合成内容渲染为 Bitmap ,然后将其与应用程序小部件中的 ImageView 一起使用,但仅此而已.

If you mean Compose UI and related packages — the library of composables that we can use to build the UIs displayed by activities — then no, this will have little role with app widgets. You could, in principle, render a composable to a Bitmap, then use that with an ImageView in an app widget, but that's about it.

如果您指的是Compose Runtime,则表示基本的管道"在 @Composable ,重构, remember()等后面,那么将来可能会提供一些东西.基本上,据我所知,可能还有另一组可组合对象与建立和发布 RemoteViews 视图层次结构相关.从好的方面来说,这将使您的 AppWidgetProvider 具有感觉".但是,它不会导致 TextField 之类的东西在应用程序小部件中神奇地开始工作.

If you mean Compose Runtime — the underlying "plumbing" behind @Composable, recomposition, remember(), and so on — then there may be something offered in the future. Basically, as I understand it, there might be another set of composables tied to building up and publishing a RemoteViews view hierarchy. On the plus side, this will give your AppWidgetProvider a Compose "feel". However, it will not cause something like TextField to start working magically in an app widget.

这篇关于可以使用Jetpack Compose来构建App窗口小部件吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆