TextField und OutlinedTextField
Lesen Sie, was der Nutzer eingibt.
TextField und OutlinedTextField ist eine kostenlose Jetpack Compose Academy-Lektion auf CoddyKit. Dies ist Lektion 1 von 4. Du kannst die komplette Lektion unten kostenlos lesen – dann übst du sie direkt im Browser mit einem integrierten Code-Editor und einem KI-Tutor rund um die Uhr. Sie ist Teil des Jetpack Compose Academy-Lernpfads, und dein Fortschritt wird über Web und CoddyKit-App synchronisiert. Der Jetpack Compose Academy-Kurs umfasst insgesamt 4 Lektionen.
Teile dieser Lektion wurden noch nicht übersetzt und werden auf Englisch angezeigt.
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. 🎉
Häufig gestellte Fragen
Ist die Lektion „TextField und OutlinedTextField“ kostenlos?
Ja — der vollständige Text von „TextField und OutlinedTextField“ ist hier im Web kostenlos zu lesen. Um sie interaktiv zu üben (integrierter Code-Editor und 24/7 KI-Tutor) und den Rest des Jetpack Compose Academy-Kurses freizuschalten, upgrade auf CoddyKit PRO. Der Jetpack Compose Academy-Kurs umfasst insgesamt 4 Lektionen.
Was lerne ich in „TextField und OutlinedTextField“?
Lesen Sie, was der Nutzer eingibt. Du übst Jetpack Compose Academy mit praktischem Code, den du direkt im Browser ausführst, und ein 24/7 KI-Tutor beantwortet deine Fragen während du die Lektion bearbeitest.
Brauche ich Erfahrung, um Jetpack Compose Academy zu starten?
Keine Vorkenntnisse erforderlich. Jetpack Compose Academy auf CoddyKit ist für Anfänger bis fortgeschrittene Lernende strukturiert, sodass du hier starten oder von Anfang an beginnen und in deinem eigenen Tempo voranschreiten kannst. Dies ist Lektion 1 von 4.
Wie lange dauert die Lektion „TextField und OutlinedTextField“?
Die meisten CoddyKit-Lektionen dauern etwa 5–10 Minuten. Jede ist kompakt und interaktiv, sodass du stetig Fortschritte machst und genau dort weitermachst, wo du aufgehört hast – im Web und in der App.
Kann ich in dieser Jetpack Compose Academy-Lektion Code schreiben und ausführen?
Ja. Jede Jetpack Compose Academy-Lektion enthält einen integrierten Code-Editor, sodass du echten Code direkt in deinem Browser schreibst und ausführst und sofort KI-Feedback erhältst — ohne lokale Einrichtung erforderlich.
Alle Lektionen in diesem Kurs
- TextField und OutlinedTextField
- Labels, Platzhalter und führende Icons
- Tastaturtypen und IME-Aktionen
- Inline-Validierung und Fehlerzustände