一、概念
ComposeView负责对Android平台的Activity窗口的适配,AndroidComposeView负责连接LayoutNode视图系统与View视图系统。
二、View中使用Compose
<androidx.compose.ui.platform.ComposeView
android:id="@+id/composeView"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
val composeView = findViewById<ComposeView>(R.id.composeView)
composeView.setContent { }
三、Compose中使用View
@Composable
fun SwipeableSample(str: String) {
val content = remember(str){ Html.fromHtml(str, 1) }
AndroidView(
factory = { context ->
TextView(context).apply {
movementMethod = LinkMovementMethod.getInstance() //超链接可点击
}
},
update = {textView ->
textView.text = content
}
)
}