【问题标题】:What is ComposeViewAdapter used for in Jetpack Compose?ComposeViewAdapter 在 Jetpack Compose 中的用途是什么?
【发布时间】:2021-11-09 09:20:56
【问题描述】:

我在com.example.Example.kt中有一个简单的可组合函数:

@Preview
@Composable fun ExampleComposable() {
    Text("Hello")
}

我尝试使用 ComposeViewAdapter,如下所示:

<androidx.compose.ui.tooling.ComposeViewAdapter
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:composableName="com.example.ExampleKt" />

Android Studio 不会在设计窗格中显示任何可组合项的预览。

另外,ComposeViewAdapterandroidx.compose.ui.platform.ComposeView 有何不同?

【问题讨论】:

    标签: android android-xml android-jetpack-compose android-jetpack


    【解决方案1】:

    Example.kt文件可以有很多composable,需要指定composable名称:

    <androidx.compose.ui.tooling.ComposeViewAdapter
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:composableName="com.example.ExampleKt.ExampleComposable" />
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-01-10
      • 1970-01-01
      • 1970-01-01
      • 2018-10-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-01
      相关资源
      最近更新 更多