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

androidx.compose.ui.platform

Interfaces

AndroidOwner

Interface to be implemented by Owners able to handle Android View specific functionality.

ClipboardManager

Interface for managing the Clipboard.

InspectableParameter

A compose parameter that is inspectable by tools.

TextToolbar

Interface for text-related toolbar.

UriHandler

An interface of providing platform specific URL handling.

Classes

AbstractComposeView

Base class for custom android.view.Views implemented using Jetpack Compose UI.

AndroidUriHandler

AtomicInt

ComposeView

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

ParameterElement

A parameter element describes the elements of a compose parameter instance.

Enums

TextToolbarStatus

Status of the TextToolbar.

Top-level functions summary

AndroidOwner
AndroidOwner(context: Context, lifecycleOwner: LifecycleOwner? = null, viewModelStoreOwner: ViewModelStoreOwner? = null, savedStateRegistryOwner: SavedStateRegistryOwner? = null)

Composition
subcomposeInto(container: LayoutNode, parent: CompositionReference? = null, composable: () -> Unit)

Composition
subcomposeInto(container: LayoutNode, recomposer: Recomposer, parent: CompositionReference? = null, composable: () -> Unit)

Top-level properties summary

ProvidableAmbient<AnimationClockObservable>

The default animation clock used for animations when an explicit clock isn't provided.

ProvidableAmbient<Autofill?>

The ambient that can be used to trigger autofill actions.

ProvidableAmbient<AutofillTree>

The ambient that can be used to add AutofillNodes to the autofill tree.

ProvidableAmbient<ClipboardManager>

The ambient to provide communication with platform clipboard service.

ProvidableAmbient<Configuration>

The Android Configuration.

ProvidableAmbient<Context>

Provides a Context that can be used by Android applications.

ProvidableAmbient<Density>

Provides the Density to be used to transform between density-independent pixelunits (DP) and pixel units or scale-independent pixel units (SP) and pixel units.

ProvidableAmbient<HapticFeedback>

The ambient to provide haptic feedback to the user.

ProvidableAmbient<Boolean>

Inspectable mode ambient.

ProvidableAmbient<LayoutDirection>

The ambient to provide the layout direction.

ProvidableAmbient<LifecycleOwner>

The ambient containing the current LifecycleOwner.

ProvidableAmbient<TextInputService?>

The ambient to provide communication with platform text input service.

ProvidableAmbient<TextToolbar>

The ambient to provide text-related toolbar.

ProvidableAmbient<UriHandler>

The ambient to provide functionality related to URL, e.

ProvidableAmbient<View>

The ambient containing the current Compose View.

ProvidableAmbient<ViewModelStoreOwner>

The ambient containing the current ViewModelStoreOwner.

Extension functions summary

For android.app.Activity
Composition
Activity.setViewContent(composable: () -> Unit)

Sets the contentView of an activity to a FrameLayout, and composes the contents of the layout with the passed in composable.

For 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.

For androidx.activity.ComponentActivity
Composition
ComponentActivity.setContent(recomposer: Recomposer = Recomposer.current(), content: () -> Unit)

Composes the given composable into the given activity.

For Modifier
Modifier

Applies a tag to allow modified element to be found in tests.

Top-level functions

AndroidOwner

fun AndroidOwner(
    context: Context,
    lifecycleOwner: LifecycleOwner? = null,
    viewModelStoreOwner: ViewModelStoreOwner? = null,
    savedStateRegistryOwner: SavedStateRegistryOwner? = null
): AndroidOwner

This function creates an instance of AndroidOwner

Parameters
context: Context Context to use to create a View
lifecycleOwner: LifecycleOwner? = null Current LifecycleOwner. When it is not provided we will try to get the owner using ViewTreeLifecycleOwner when we will be attached.
viewModelStoreOwner: ViewModelStoreOwner? = null Current ViewModelStoreOwner. When it is not provided we will try to get the owner using ViewTreeViewModelStoreOwner when we will be attached.
savedStateRegistryOwner: SavedStateRegistryOwner? = null Current SavedStateRegistryOwner. When it is not provided we will try to get the owner using ViewTreeSavedStateRegistryOwner when we will be attached.

subcomposeInto

@MainThread fun subcomposeInto(
    container: LayoutNode,
    parent: CompositionReference? = null,
    composable: () -> Unit
): Composition

Deprecated.

subcomposeInto

@MainThread fun subcomposeInto(
    container: LayoutNode,
    recomposer: Recomposer,
    parent: CompositionReference? = null,
    composable: () -> Unit
): Composition

Top-level properties

AnimationClockAmbient

val AnimationClockAmbient: ProvidableAmbient<AnimationClockObservable>

The default animation clock used for animations when an explicit clock isn't provided.

AutofillAmbient

val AutofillAmbient: ProvidableAmbient<Autofill?>

The ambient that can be used to trigger autofill actions. Eg. Autofill.requestAutofillForNode.

AutofillTreeAmbient

val AutofillTreeAmbient: ProvidableAmbient<AutofillTree>

The ambient that can be used to add AutofillNodes to the autofill tree. The AutofillTree is a temporary data structure that will be replaced by Autofill Semantics (b/138604305).

ClipboardManagerAmbient

val ClipboardManagerAmbient: ProvidableAmbient<ClipboardManager>

The ambient to provide communication with platform clipboard service.

ConfigurationAmbient

val ConfigurationAmbient: ProvidableAmbient<Configuration>

The Android Configuration. The Configuration is useful for determining how to organize the UI.

ContextAmbient

val ContextAmbient: ProvidableAmbient<Context>

Provides a Context that can be used by Android applications.

DensityAmbient

val DensityAmbient: ProvidableAmbient<Density>

Provides the Density to be used to transform between density-independent pixelunits (DP) and pixel units or scale-independent pixel units (SP) and pixel units. This is typically used when a DP is provided and it must be converted in the body of Layout or DrawModifier.

HapticFeedBackAmbient

val HapticFeedBackAmbient: ProvidableAmbient<HapticFeedback>

The ambient to provide haptic feedback to the user.

InspectionMode

val InspectionMode: ProvidableAmbient<Boolean>

Inspectable mode ambient. True if the composition is composed inside a Inspectable component.

LayoutDirectionAmbient

val LayoutDirectionAmbient: ProvidableAmbient<LayoutDirection>

The ambient to provide the layout direction.

LifecycleOwnerAmbient

val LifecycleOwnerAmbient: ProvidableAmbient<LifecycleOwner>

The ambient containing the current LifecycleOwner.

TextInputServiceAmbient

val TextInputServiceAmbient: ProvidableAmbient<TextInputService?>

The ambient to provide communication with platform text input service.

TextToolbarAmbient

val TextToolbarAmbient: ProvidableAmbient<TextToolbar>

The ambient to provide text-related toolbar.

UriHandlerAmbient

val UriHandlerAmbient: ProvidableAmbient<UriHandler>

The ambient to provide functionality related to URL, e.g. open URI.

ViewAmbient

val ViewAmbient: ProvidableAmbient<View>

The ambient containing the current Compose View.

ViewModelStoreOwnerAmbient

val ViewModelStoreOwnerAmbient: ProvidableAmbient<ViewModelStoreOwner>

The ambient containing the current ViewModelStoreOwner.

Extension functions

setContent

fun ViewGroup.setContent(
    recomposer: Recomposer,
    parentComposition: CompositionReference? = null,
    content: () -> Unit
): Composition

Composes the given composable into the given view.

The new composition can be logically "linked" to an existing one, by providing a non-null parentComposition. This will ensure that invalidations and ambients will flow through the two compositions as if they were not separate.

Note that this ViewGroup should have an unique id for the saved instance state mechanism to be able to save and restore the values used within the composition. See View.setId.

Parameters
recomposer: Recomposer The Recomposer to coordinate scheduling of composition updates.
parentComposition: CompositionReference? = null The parent composition reference, if applicable.
content: () -> Unit Composable that will be the content of the view.

setContent

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

Deprecated.

Composes the given composable into the given view.

Note that this ViewGroup should have an unique id for the saved instance state mechanism to be able to save and restore the values used within the composition. See View.setId.

Parameters
content: () -> Unit Composable that will be the content of the view.

setContent

fun ComponentActivity.setContent(
    recomposer: Recomposer = Recomposer.current(),
    content: () -> Unit
): Composition

Composes the given composable into the given activity. The content will become the root view of the given activity.

Composition.dispose is called automatically when the Activity is destroyed.

Parameters
recomposer: Recomposer = Recomposer.current() The Recomposer to coordinate scheduling of composition updates
content: () -> Unit A @Composable function declaring the UI contents

setViewContent

fun Activity.setViewContent(composable: () -> Unit): Composition

Deprecated.

Sets the contentView of an activity to a FrameLayout, and composes the contents of the layout with the passed in composable.

setViewContent

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

Deprecated.

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

testTag

@Stable fun Modifier.testTag(tag: String): Modifier

Applies a tag to allow modified element to be found in tests.

This is a convenience method for a semantics that sets SemanticsPropertyReceiver.testTag.