- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在我的项目中,我使用 JetPack Compose 和 AndroidView 来使用 XML View 。
@Composable
fun MyComposable(
message: String
) {
AndroidView(
factory = { context ->
TextView(context).apply {
text = message
}
})
}
我的问题是当我的
message
状态变化,
AndroidView
中的 XML View 没有重组。
AndroidView
中有一个选项观察状态变化?
MyComposable
例如
最佳答案
您可以使用 update
堵塞。
来自 doc :
The
update
block can be run multiple times (on the UI thread as well) due to recomposition, and it is the right place to setView
properties depending on state. When state changes, the block will be reexecuted to set the new properties. Note the block will also be ran once right after thefactory
block completes
AndroidView(
factory = { context ->
TextView(context).apply {
text = "Initial Value"
}
},
update = {
it.text = message
}
)
关于android - 在 JetPack Compose 中手动重构所有 AndroidView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67916613/
来自 AndroidView documentation : AndroidView will clip its content to the layout bounds, as being clip
在我的项目中,我使用 JetPack Compose 和 AndroidView 来使用 XML View 。 @Composable fun MyComposable( message: S
在 Jetpack Compose 中,我有一个 AndroidView使用一个监听器读取传递的状态,如下所示: @Composable fun Scanner( state: Scanner
很可能是一个新手问题,因为我对 Android 开发人员还很陌生 - 我在配置更改/导航时在 @Composable 中保留 AndroidView 的状态时遇到了麻烦,因为工厂 block 被调用(
我有一个应用程序可以显示封装在 AndroidView 中的多个不同 View 。在下面要重现的简单示例中,这些只是 TextView 实例。问题是更改文本(在本例中循环显示三个不同的值)似乎不会更新
我希望 RecyclerView 在列表更改时动态更改。 View 根据 AndroidView.update 表达式进行重构。然而我尝试过的都不起作用。我不熟悉 RecyclerViews,我认为这
我是一名优秀的程序员,十分优秀!