Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is ComposeViewAdapter used for in Jetpack Compose?

I have a simple composable function in com.example.Example.kt:

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

I tried to use ComposeViewAdapter like below:

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

Android Studio does not show any preview of the composable in the design pane.

Also, how is ComposeViewAdapter different from androidx.compose.ui.platform.ComposeView?

like image 679
Mahozad Avatar asked Sep 12 '25 13:09

Mahozad


1 Answers

Example.kt file can have many composables, you need to specify the composable name:

<androidx.compose.ui.tooling.ComposeViewAdapter
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:composableName="com.example.ExampleKt.ExampleComposable" />
like image 185
Philip Dukhov Avatar answered Sep 15 '25 03:09

Philip Dukhov