androidx.compose.ui.autofill

Interfaces

Autofill

This interface is deprecated. You no longer have to call these apis when focus changes.

Cmn
ContentDataType

Content data type information.

Cmn
android
ContentType

Content type information.

Cmn
android
FillableData

Represents a single piece of data for autofill purposes.

Cmn

Classes

AutofillManager

Autofill API.

Cmn
AutofillNode

This class is deprecated. Use the new semantics-based Autofill APIs androidx.compose.ui.autofill.ContentType and androidx.compose.ui.autofill.ContentDataType instead.

Cmn
AutofillTree

This class is deprecated. Use the new semantics-based Autofill APIs androidx.compose.ui.autofill.ContentType and androidx.compose.ui.autofill.ContentDataType instead.

Cmn

Enums

AutofillType

This enum is deprecated. Use the new semantics-based API and androidx.compose.ui.autofill.ContentType instead.

Cmn

Top-level functions summary

ContentDataType
ContentDataType(dataType: Int)
android
ContentType
ContentType(contentHint: String)

Create a custom ContentType with contentHint.

android
FillableData?
FillableData(autofillValue: AutofillValue)

Creates a FillableData from the platform AutofillValue type.

android
FillableData?
FillableData(booleanValue: Boolean)

Creates a FillableData instance from a Boolean.

Cmn
android
FillableData?
FillableData(listIndexValue: Int)

Creates a FillableData instance from an Int.

Cmn
android
FillableData?

Creates a FillableData instance from a CharSequence.

Cmn
android

Extension functions summary

Modifier

Set autofill hint with contentType.

Cmn
AutofillValue?

Retrieves the underlying platform AutofillValue from the FillableData.

android

Extension properties summary

Top-level functions

ContentDataType

fun ContentDataType(dataType: Int): ContentDataType

ContentType

fun ContentType(contentHint: String): ContentType

Create a custom ContentType with contentHint.

This creates a ContentType with the parameter contentHint passed in. This API can be used if the Autofill hint is not present in the list of contentTypes provided by Compose.

For example, ContentType(androidx.autofill.HintConstants.AUTOFILL_HINT_FLIGHT_CONFIRMATION_CODE) can be used to create a new flight confirmation code hint.

FillableData

fun FillableData(autofillValue: AutofillValue): FillableData?

Creates a FillableData from the platform AutofillValue type.

Parameters
autofillValue: AutofillValue

The platform autofill value to create the FillableData from.

Returns
FillableData?

A FillableData object containing the platform autofill data, or null if the platform version is lower than Build.VERSION_CODES.O.

FillableData

fun FillableData(booleanValue: Boolean): FillableData?

Creates a FillableData instance from a Boolean.

This function is used to wrap a boolean value for autofill purposes, such as the state of a checkbox or a switch.

Parameters
booleanValue: Boolean

The boolean data to be used for autofill.

Returns
FillableData?

A FillableData object containing the boolean data, or null if the platform does not support autofill.

FillableData

fun FillableData(listIndexValue: Int): FillableData?

Creates a FillableData instance from an Int.

This function is used to wrap an integer value for autofill purposes, such as the selected index in a dropdown menu or spinner.

Parameters
listIndexValue: Int

The integer data to be used for autofill, representing the index of the selected item in a list.

Returns
FillableData?

A FillableData object containing the integer data, or null if the platform does not support autofill.

FillableData

fun FillableData(textValue: CharSequence): FillableData?

Creates a FillableData instance from a CharSequence.

This function is used to wrap a text value for autofill purposes.

Parameters
textValue: CharSequence

The text data to be used for autofill.

Returns
FillableData?

A FillableData object containing the text data, or null if the platform does not support autofill.

Extension functions

contentType

fun Modifier.contentType(contentType: ContentType): Modifier

Set autofill hint with contentType.

This applies the contentType to the modifier's semantics, in turn enabling autofill and marking the hint to be associated with this composable. This allows autofill frameworks to provide relevant suggestions to users.

Using contentType is equivalent to simply setting the contentType semantic property, i.e. Modifier.contentType(ContentType.NewUsername) is equivalent to setting Modifier.semantics { contentType = ContentType.NewUsername }.

import androidx.compose.foundation.text.input.rememberTextFieldState
import androidx.compose.material.Text
import androidx.compose.material.TextField
import androidx.compose.ui.Modifier
import androidx.compose.ui.autofill.ContentType
import androidx.compose.ui.autofill.contentType
import androidx.compose.ui.semantics.contentType

TextField(
    state = rememberTextFieldState(),
    label = { Text("Enter your new username here.") },
    // Set the content type hint with the modifier extension.
    modifier = Modifier.contentType(ContentType.NewUsername),
)
import androidx.compose.foundation.text.input.rememberTextFieldState
import androidx.compose.material.Text
import androidx.compose.material.TextField
import androidx.compose.ui.Modifier
import androidx.compose.ui.autofill.ContentType
import androidx.compose.ui.autofill.contentType
import androidx.compose.ui.semantics.contentType
import androidx.compose.ui.semantics.semantics

TextField(
    state = rememberTextFieldState(),
    label = { Text("Enter your new password here.") },
    // Set the content type hint with semantics.
    modifier = Modifier.semantics { contentType = ContentType.NewPassword },
)
Parameters
contentType: ContentType

The ContentType to apply to the component's semantics.

Returns
Modifier

The Modifier with the specified ContentType semantics set.

toAutofillValue

fun FillableData.toAutofillValue(): AutofillValue?

Retrieves the underlying platform AutofillValue from the FillableData.

Returns
AutofillValue?

The platform AutofillValue, or null if the FillableData is not an instance of AndroidFillableData or the platform version is lower than Build.VERSION_CODES.O.

Extension properties

dataType

val ContentDataType.dataTypeInt