Search code examples
androidandroid-textinputlayoutandroid-jetpack-composeandroid-compose-textfield

Jetpack Compose: Disable Interaction with TextField


Is there a way to disable all interaction for Jetpack Compose's TextField?


Solution

  • You can use the enabled attribute:

    enabled : controls the enabled state of the TextField. When false, the text field will be neither editable nor focusable, the input of the text field will not be selectable, visually text field will appear in the disabled UI state

    Something like:

    var text by rememberSaveable { mutableStateOf("Text") }
    
    TextField(
        value = text,
        onValueChange = { text = it },
        enabled = false,
        label = { Text("Label") },
        singleLine = true
    )