Compose (14) - 与View互操作

一、概念

在这里插入图片描述

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
        }
    )
}

猜你喜欢

转载自blog.csdn.net/HugMua/article/details/130097223
14
今日推荐