Property

hintText

The hint text for an editable text field.

HintTextSample

@Sampled
@Composable
fun HintTextSample() {
    val label = "Label" // In an application, this hint would typically be a localized String.
    val state = rememberTextFieldState()
    BasicTextField(
        state = state,
        modifier = Modifier.semantics { hintText = label },
        decorator = { innerTextField ->
            Box {
                innerTextField()
                if (state.text.isEmpty()) {
                    // Hide this visual placeholder from talkback to prevent duplicated
                    // announcements, as the parent BasicTextField already provides the hintText.
                    Text(text = label, modifier = Modifier.semantics { hideFromAccessibility() })
                }
            }
        },
    )
}
Jetpack Compose beyond MaterialFree components, screens and templates for apps that don’t look like Google’s. Copy them into your app, or let your coding agent add them.Browse for free

Content updated: