material3-theming
Skill0 starsChanged 33 days agoMITView on GitHub
Material 3 theming discipline in Compose: read colors, typography and shapes through MaterialTheme (no hardcoded values in UI code), no Material 2 components or theme accessors in an M3 app, dynamic color with a custom fallback. Use when writing or reviewing Compose UI and theme files. Core rules have machine checks in checks/.
In this repository11 other files it gives its agents.
- android-testingSkill
- compose-architectureSkill
- compose-migrationSkill
- compose-multiplatformSkill
- compose-performanceSkill
- compose-testingSkill
- dependency-injectionSkill
- gradle-build-logicSkill
- kmp-fundamentalsSkill
- offline-firstSkill
- release-engineeringSkill
The file
We split this skill into the rules it gives an agent
8 rules. About 0 are common, 3 are distinctive, and 5 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈3
Distinctive · estimate
This author's own choices. Worth a look.
5
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 15
After ANY Compose UI or theme edit, run the Verification step (bottom of this file).
- Very specific: line 20
MUST read colors through MaterialTheme.colorScheme color roles: "You can access Material theme colors in your app via …
- Very specific: line 22
MUST NOT hardcode Color(0x...) literals, colorResource(R.color...) lookups, or R.color...
- Very specific: line 52
MUST style text with theme styles: "You can retrieve the typography provided to the M3 MaterialTheme composable by using …
- Very specific: line 70
MUST NOT import androidx.compose.material.* (Material 2) components in a Material 3 app — M2 components read the M2 theme, so the app's M3 …
- Distinctive: line 93
MUST support dynamic color on Android 12+ with a custom light/dark fallback: "Dynamic color is available on Android 12 and above.
- Distinctive: line 115
Run after every Compose UI/theme edit (from the project root):
- Very specific: line 124
All four must pass (exit 0) before declaring the task done.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Material 3 Theming
Operational rules for a coding agent. RIGHT/WRONG pairs are canonical. After ANY Compose UI or theme edit, run the Verification step (bottom of this file). This skill targets Material 3 apps.
1. Colors come from MaterialTheme.colorScheme
MUST read colors through MaterialTheme.colorScheme color roles: "You can
access Material theme colors in your app via MaterialTheme.colorScheme."
MUST NOT hardcode Color(0x...) literals, colorResource(R.color...)
lookups, or R.color... references in composable files — hardcoded pairs
break dark theme and dynamic color, and the docs call for accessible role
pairing: "Use on-primary on top of primary, and on-primary-container on
top of primary-container."
WRONG:
Text(
text = name,
color = Color(0xFF1B6EF3), // bypasses the theme
modifier = Modifier.background(Color(0xFFEEEEEE)),
)RIGHT:
Text(
text = name,
color = MaterialTheme.colorScheme.onSurface,
modifier = Modifier.background(MaterialTheme.colorScheme.surface),
)Palette definitions belong in the theme: lightColorScheme(...) /
darkColorScheme(...) values live in Theme.kt / Color.kt, which the
check excludes by filename.
2. Typography comes from MaterialTheme.typography
MUST style text with theme styles: "You can retrieve the typography
provided to the M3 MaterialTheme composable by using
MaterialTheme.typography." MUST NOT set fontSize = ... in composable
files — text sizes are customized in the Typography(...) passed to the
theme, not ad hoc per composable.
WRONG:
Text(text = "Hello", fontSize = 18.sp)RIGHT:
Text(text = "Hello", style = MaterialTheme.typography.titleMedium)3. No Material 2 in an M3 app
MUST NOT import androidx.compose.material.* (Material 2) components in a
Material 3 app — M2 components read the M2 theme, so the app's M3
colorScheme/typography silently does not apply to them (and two Button
implementations coexist in the app). Material icons
(androidx.compose.material.icons) are shared and are not flagged.
WRONG:
import androidx.compose.material.Button // M2RIGHT:
import androidx.compose.material3.ButtonRelated mixed-API bug: MaterialTheme.colors is the M2 accessor — the M3
accessor is MaterialTheme.colorScheme. A file importing material3 while
reading MaterialTheme.colors compiles (M2 is on the classpath) but reads
the wrong theme.
4. Dynamic color with a custom fallback
MUST support dynamic color on Android 12+ with a custom light/dark
fallback: "Dynamic color is available on Android 12 and above. If dynamic
color is available, you can set up a dynamic ColorScheme. If not, you
should fall back to using a custom light or dark ColorScheme." Dark theme
comes from isSystemInDarkTheme().
RIGHT (canonical shape):
val dynamicColor = Build.VERSION.SDK_INT >= Build.VERSION_CODES.S
val colorScheme = when {
dynamicColor && darkTheme -> dynamicDarkColorScheme(LocalContext.current)
dynamicColor && !darkTheme -> dynamicLightColorScheme(LocalContext.current)
darkTheme -> DarkColors
else -> LightColors
}This section is review-verified (no deterministic check): the checks cannot see whether your Theme composable implements this shape.
Verification
Run after every Compose UI/theme edit (from the project root):
bash <skill-dir>/checks/check_no_hardcoded_colors.sh <compose-src-dir>
bash <skill-dir>/checks/check_no_hardcoded_font_size.sh <compose-src-dir>
bash <skill-dir>/checks/check_no_material2_imports.sh <compose-src-dir>
bash <skill-dir>/checks/check_m2_theme_accessor.sh <compose-src-dir>All four must pass (exit 0) before declaring the task done. Checks are deterministic heuristics — they catch the documented anti-patterns above, not every theming bug. §4 is verified by review against references/material3.md.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

