MaterialTheme und Farbschemata
Definieren Sie die Farbpalette Ihrer App an einer zentralen Stelle.
MaterialTheme und Farbschemata 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.
One Theme to Rule Them
MaterialTheme is the wrapper that hands colors, fonts, and shapes to every Composable inside it, so you style your app in one place. 🎨
Wrap Your App
You usually wrap your whole UI in your app theme, which calls MaterialTheme at its core. Everything inside then reads from that single source.
AppTheme {
// your screens go here
}The colorScheme Slot
The first thing colorScheme defines is your palette: the named colors every Material component reaches for automatically.
MaterialTheme(
colorScheme = lightColorScheme()
) { /* app */ }Roles, Not Raw Colors
Material 3 uses color roles like primary and surface instead of raw hex everywhere, so components stay consistent and easy to retheme.
primary & onPrimary
The primary role is your brand color for key actions, and onPrimary is the readable color drawn on top of it, like white text on a blue button.
Surfaces & Backgrounds
The surface and background roles paint cards, sheets, and the screen behind everything, while onSurface keeps content legible on them.
Build a Light Scheme
You craft a palette with lightColorScheme, overriding only the roles you care about and letting sensible defaults fill the rest.
val scheme = lightColorScheme(
primary = Color(0xFF1A73E8)
)Read a Color in Code
Inside any Composable you grab theme colors through MaterialTheme.colorScheme, so a color change in the theme flows everywhere at once.
val c = MaterialTheme.colorScheme.primaryTint a Surface
Pass a role into a Composable and it stays on-theme; here a Surface paints itself with the primary color from the active colorScheme.
Surface(color = MaterialTheme.colorScheme.primary) {
Text("Hi")
}Container Roles
Roles like primaryContainer give softer, tonal backgrounds for chips and highlights, paired with onPrimaryContainer for their text.
Retheme in Seconds
Because components ask the theme for colors, swapping one colorScheme instantly restyles the entire app, with no per-widget edits. ✨
Quick Check
Where do your app-wide colors live in Material 3?
Recap: One Palette, Everywhere
You wrapped your app in MaterialTheme, defined a colorScheme of roles, and read colors back in code so one palette styles the whole UI. 🎉
Häufig gestellte Fragen
Ist die Lektion „MaterialTheme und Farbschemata“ kostenlos?
Ja — der vollständige Text von „MaterialTheme und Farbschemata“ 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 „MaterialTheme und Farbschemata“?
Definieren Sie die Farbpalette Ihrer App an einer zentralen Stelle. 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 „MaterialTheme und Farbschemata“?
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
- MaterialTheme und Farbschemata
- Typografie- und Form-Tokens
- Dark Mode und dynamische Farben
- Ein benutzerdefiniertes Designsystem erstellen