Google is committed to advancing racial equity for Black communities. See how.

ComposeView

class ComposeView : AbstractComposeView
kotlin.Any
   ↳ android.view.View
   ↳ android.view.ViewGroup
   ↳ androidx.compose.ui.platform.AbstractComposeView
   ↳ androidx.compose.ui.platform.ComposeView

A android.view.View that can host Jetpack Compose UI content. Use setContent to supply the content composable function for the view.

This android.view.View requires that the window it is attached to contains a ViewTreeLifecycleOwner. This androidx.lifecycle.LifecycleOwner is used to dispose of the underlying composition when the host Lifecycle is destroyed, permitting the view to be attached and detached repeatedly while preserving the composition. Call disposeComposition to dispose of the underlying composition earlier, or if the view is never initially attached to a window. (The requirement to dispose of the composition explicitly in the event that the view is never (re)attached is temporary.)

Summary

Public constructors
<init>(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0)

A android.view.View that can host Jetpack Compose UI content.

Public methods
Unit

The Jetpack Compose UI content for this view.

Unit
setContent(content: () -> Unit)

Set the Jetpack Compose UI content for this view.

Inherited functions
Inherited extension functions
From androidx.ui.test.android.view.View
Bitmap

Captures the underlying view's surface into bitmap.

From androidx.compose.ui.platform.android.view.ViewGroup
Composition
ViewGroup.setContent(recomposer: Recomposer, parentComposition: CompositionReference? = null, content: () -> Unit)

Composes the given composable into the given view.

Composition
ViewGroup.setContent(content: () -> Unit)

Composes the given composable into the given view.

Composition
ViewGroup.setViewContent(parent: CompositionReference? = null, composable: () -> Unit)

Composes the children of the view with the passed in composable.

Inherited properties

Public constructors

<init>

ComposeView(
    context: Context,
    attrs: AttributeSet? = null,
    defStyleAttr: Int = 0)

A android.view.View that can host Jetpack Compose UI content. Use setContent to supply the content composable function for the view.

This android.view.View requires that the window it is attached to contains a ViewTreeLifecycleOwner. This androidx.lifecycle.LifecycleOwner is used to dispose of the underlying composition when the host Lifecycle is destroyed, permitting the view to be attached and detached repeatedly while preserving the composition. Call disposeComposition to dispose of the underlying composition earlier, or if the view is never initially attached to a window. (The requirement to dispose of the composition explicitly in the event that the view is never (re)attached is temporary.)

Public methods

Content

@Composable fun Content(): Unit

The Jetpack Compose UI content for this view. Subclasses must implement this method to provide content. Initial composition will occur when the view becomes attached to a window or when createComposition is called, whichever comes first.

setContent

fun setContent(content: () -> Unit): Unit

Set the Jetpack Compose UI content for this view. Initial composition will occur when the view becomes attached to a window or when createComposition is called, whichever comes first.