android - 在 Jetpack Compose 中使用自定义视图
问题描述
假设我正在使用一些旨在提供一些 UI 小部件的库。假设这个库提供了一个名为FancyButton
.
另一方面,我有一个使用 Android Studio 4 创建的新项目,它允许我使用Empty Compose Activity
.
问题是:
我应该如何将它添加FancyButton
到视图堆栈中?可能吗?或者对于 Jetpack Compose,我只能使用专门为 Jetpack Compose 开发的组件。在这种情况下,AFAIK 我只能使用 Android 标准组件(Text
、、MaterialTheme
等)。
如果我尝试使用这样的东西:
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
MaterialTheme {
Greeting("Android")
FancyButton(context, "Some text")
}
}
}
然后我得到这个错误:
e: Supertypes of the following classes cannot be resolved. Please make sure you have the required dependencies in the classpath.
解决方案
目前(截至0.1.0-dev04
),对此没有很好的解决方案。将来,您将能够简单地将其称为FancyButton("Some text")
(context
不需要)。
您可以在此处查看 Compose 代码中的演示。
推荐阅读
- angular - Angular 12:TypeError:teardown.unsubscribe 不是函数
- pimcore - pimcore 中的静态路由不适用于多个参数
- ansible - ansible:自定义要使用的密码管理器
- python-3.x - 数据类 + sqlalchemy(使用 mapper_registry.mapped)无法实例化对象
- json - 如何通过`jq`在一行中打印多个值?
- c - CS50 过滤器:边缘我的代码工作正常,但无法通过 cs50 检查
- r - R 无法连接到 SQLite
- react-native - 使用 expo 安装带有 NPM 的包失败
- browser - 如何在 Allure 框架中禁用缓存?
- c# - 单元测试中的模拟混淆