contentType
Common
Modifier in Compose Ui
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 }
.
Last updated:
Installation
dependencies {
implementation("androidx.compose.ui:ui:1.9.0-alpha01")
}
Overloads
fun Modifier.contentType(contentType: ContentType): Modifier
Parameters
name | description |
---|---|
contentType | The [ContentType] to apply to the component's semantics. |
Code Examples
AutofillableTextFieldWithAutofillModifier
@Composable
fun AutofillableTextFieldWithAutofillModifier() {
TextField(
state = rememberTextFieldState(),
label = { Text("Enter your new username here.") },
// Set the content type hint with the modifier extension.
modifier = Modifier.contentType(ContentType.NewUsername)
)
}
AutofillableTextFieldWithContentTypeSemantics
@Composable
fun AutofillableTextFieldWithContentTypeSemantics() {
TextField(
state = rememberTextFieldState(),
label = { Text("Enter your new password here.") },
// Set the content type hint with semantics.
modifier = Modifier.semantics { contentType = ContentType.NewPassword }
)
}