gpt4 book ai didi

android - 是否可以将 jetpack compose 与 xml 集成?

转载 作者:行者123 更新时间:2023-12-05 00:17:49 27 4
gpt4 key购买 nike

我已经在 J​​etpack Compose 中完成了整个项目(包含 3 个 Activity )。我需要用 xml 和 kotlin 完成一项 Activity ,因为我不知道如何在 jetpack 中完成(我对两者都是新手)。是否可以将新 Activity 与其余代码集成?

最佳答案

Jetpack Compose 和基于 XML View 的系统是可互操作的。

I need one activity to be done with xml

您可以添加 Android Views in Compose

一个简单的例子:

AndroidView(
viewBlock = { context ->
val myView = LayoutInflater.from(context).inflate(R.layout.my_layout, null, false)
val text = myView.findViewById<TextView>(R.id.text)
// do things
myView
},
update = { view ->
// update the view/trigger recomposition
}
)

关于android - 是否可以将 jetpack compose 与 xml 集成?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71568299/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com