Farbe, Ausrichtung und Überlauf
Färben Sie Text ein und behandeln Sie lange Inhalte elegant.
Farbe, Ausrichtung und Überlauf ist eine kostenlose Jetpack Compose Academy-Lektion auf CoddyKit. Dies ist Lektion 3 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.
Beyond Black Text
Default text adopts your theme color, but you often want a specific tint. Compose lets you set color and handle long content with ease.
Tint with color
Pass a color to recolor any Text. Use Color values directly, or pull semantic colors from MaterialTheme for theme-aware results.
Text("Error", color = Color.Red)Prefer Theme Colors
Hardcoded colors break in dark mode. Reach for MaterialTheme.colorScheme so your text stays readable on every background.
Text("Hi", color = MaterialTheme.colorScheme.primary)Align the Text
Control horizontal alignment with textAlign. Center a title or justify a paragraph; it only matters when Text has width to fill.
Text("Centered", textAlign = TextAlign.Center)Alignment Needs Width
For textAlign to show, the Text must be wider than its words, usually via fillMaxWidth. Otherwise it hugs the text and nothing shifts.
Text("Hi", modifier = Modifier.fillMaxWidth(),
textAlign = TextAlign.Center)The Overflow Problem
Real data can be longer than your space. Without a plan, text may push your layout or get awkwardly clipped. Overflow handling fixes this.
Cap with maxLines
Limit height by setting maxLines. The text will draw at most that many lines and quietly stop, keeping rows a predictable size.
Text(longBio, maxLines = 2)Show an Ellipsis
Pair maxLines with overflow = TextOverflow.Ellipsis to trail off with three dots, signaling there is more to read.
Text(longBio, maxLines = 1,
overflow = TextOverflow.Ellipsis)Other Overflow Modes
TextOverflow also offers Clip, which simply cuts at the edge, and Visible, which lets text spill out. Ellipsis is the friendliest default. 🙂
Min Lines for Stability
Use minLines to reserve space so a card does not jump in height when one item has shorter text than another in a list.
Text(caption, minLines = 2, maxLines = 2)Polished, Predictable Text
Color makes meaning clear, alignment guides the eye, and overflow rules keep layouts stable no matter how long the real data gets.
Quick Check
You want a one-line label that ends with three dots when too long. What do you set?
Recap
You learned to tint text with color, position it using textAlign, and tame long content with maxLines plus overflow. Layouts stay tidy. ✨
Häufig gestellte Fragen
Ist die Lektion „Farbe, Ausrichtung und Überlauf“ kostenlos?
Ja — der vollständige Text von „Farbe, Ausrichtung und Überlauf“ 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 „Farbe, Ausrichtung und Überlauf“?
Färben Sie Text ein und behandeln Sie lange Inhalte elegant. 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 3 von 4.
Wie lange dauert die Lektion „Farbe, Ausrichtung und Überlauf“?
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
- Die Text-Composable
- Schriftgröße, -stärke und -stil
- Farbe, Ausrichtung und Überlauf
- AnnotatedString: Formatierter gemischter Text