TextField y OutlinedTextField
Lea lo que escribe el usuario.
TextField y OutlinedTextField es una lección gratuita de Jetpack Compose Academy en CoddyKit. Esta es la lección 1 de 4. Puedes leer la lección completa abajo gratuitamente — luego la practicas en el navegador con un editor de código integrado y un tutor de IA 24/7. Forma parte de la ruta de aprendizaje de Jetpack Compose Academy, y tu progreso se sincroniza en la web y la app de CoddyKit. El curso de Jetpack Compose Academy incluye 4 lecciones en total.
Partes de esta lección aún no han sido traducidas y se muestran en inglés.
Why Text Fields Matter
Almost every app asks the user to type something. In Compose, the TextField is your gateway to reading that input. ✏️
The TextField Composable
A TextField shows an editable box. It needs a current value and a callback that fires every time the text changes.
TextField(
value = name,
onValueChange = { name = it }
)State Drives the Value
The field never stores text itself. You hold it in state and feed it back in, so the UI always shows the latest value.
var name by remember { mutableStateOf("") }onValueChange Closes the Loop
Each keystroke calls onValueChange with the new text. You save it to state, Compose redraws, and the field reflects what was typed.
onValueChange = { newText -> name = newText }Meet OutlinedTextField
OutlinedTextField works exactly the same way, but draws a clean border around the input instead of a filled background.
OutlinedTextField(
value = name,
onValueChange = { name = it }
)Filled vs Outlined
The filled TextField has a shaded box and underline. The outlined one is lighter and airier. They behave identically, so pick by style.
Add a Label
A label tells the user what the field is for. It floats above the text once the field is focused or filled.
OutlinedTextField(
value = name,
onValueChange = { name = it },
label = { Text("Name") }
)Single Line by Default
Set singleLine to true to keep input on one row. The keyboard then shows a Done action instead of a newline.
TextField(
value = name,
onValueChange = { name = it },
singleLine = true
)Read the Value Anywhere
Because the text lives in state, any other Composable can read it. Greet the user the moment they finish typing their name. 👋
Text("Hello, " + name)It Is a Controlled Field
Compose fields are controlled: what you display is whatever you pass as value. Forget to update state and the field appears frozen.
Start Simple, Grow Later
A value plus an onValueChange is all you truly need. Labels, icons, and validation are extras you add on top.
Quick Check
Which parameter receives the user's new text on every keystroke?
Recap
You met TextField and OutlinedTextField: bind a value from state, update it in onValueChange, and add a label. That is text input in Compose. 🎉
Preguntas frecuentes
¿La lección «TextField y OutlinedTextField» es gratis?
Sí — el texto completo de «TextField y OutlinedTextField» es gratis para leer aquí en la web. Para practicarla de forma interactiva (editor de código integrado y tutor de IA 24/7) y desbloquear el resto del curso de Jetpack Compose Academy, actualiza a CoddyKit PRO. El curso de Jetpack Compose Academy incluye 4 lecciones en total.
¿Qué aprenderé en «TextField y OutlinedTextField»?
Lea lo que escribe el usuario. Practicas Jetpack Compose Academy con código real que ejecutas directamente en el navegador, y un tutor de IA 24/7 responde tus preguntas mientras trabajas en la lección.
¿Necesito experiencia previa para empezar Jetpack Compose Academy?
No se requiere experiencia previa. Jetpack Compose Academy en CoddyKit está estructurado para principiantes hasta estudiantes avanzados, así que puedes empezar aquí o desde el inicio y avanzar a tu ritmo. Esta es la lección 1 de 4.
¿Cuánto tiempo toma la lección «TextField y OutlinedTextField»?
La mayoría de las lecciones de CoddyKit toman alrededor de 5–10 minutos. Cada una es compacta e interactiva, así que avanzas constantemente y retomas exactamente por donde dejaste en la web y la app.
¿Puedo escribir y ejecutar código en esta lección de Jetpack Compose Academy?
Sí. Cada lección de Jetpack Compose Academy incluye un editor de código integrado, así que escribes y ejecutas código real directamente en tu navegador y obtienes retroalimentación instantánea de IA — sin configuración local necesaria.
Todas las lecciones de este curso
- TextField y OutlinedTextField
- Etiquetas, marcadores de posición e iconos iniciales
- Tipos de teclado y acciones IME
- Validación en línea y estados de error