Jetpack Compose EditText/TextField Sample

December 15, 2021
@Composable
fun CardContent() {
    var title by rememberSaveable { mutableStateOf("") }
    var content by rememberSaveable { mutableStateOf("") }

    val modifier = Modifier.fillMaxWidth()

    Column(modifier = Modifier.padding(4.dp)) {
        // OutlinedTextField
        TextField(
            modifier = modifier,
            value = title,
            onValueChange = { title = it },
            label = { Text("Title") },
            singleLine = true
        )
        
        Spacer(modifier = Modifier.padding(4.dp))

        // sadly, minLines is yet to be supported
        TextField(
            modifier = modifier,
            value = content,
            onValueChange = { content = it },
            // maxLines = 5,
            label = { Text("Content") },
            placeholder = { Text("Write something")  },
        )
    }
}

This work is licensed under a
Creative Commons Attribution-NonCommercial 4.0 International License.