agentleFS
wrinfotelwrinfotel/verified-android-skills/skills/material3-theming/SKILL.md

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/.

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
  1. Distinctive:

    After ANY Compose UI or theme edit, run the Verification step (bottom of this file).

    line 15
  2. Very specific:

    MUST read colors through MaterialTheme.colorScheme color roles: "You can access Material theme colors in your app via …

    line 20
  3. Very specific:

    MUST NOT hardcode Color(0x...) literals, colorResource(R.color...) lookups, or R.color...

    line 22
  4. Very specific:

    MUST style text with theme styles: "You can retrieve the typography provided to the M3 MaterialTheme composable by using …

    line 52
  5. Very specific:

    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 …

    line 70
  6. Distinctive:

    MUST support dynamic color on Android 12+ with a custom light/dark fallback: "Dynamic color is available on Android 12 and above.

    line 93
  7. Distinctive:

    Run after every Compose UI/theme edit (from the project root):

    line 115
  8. Very specific:

    All four must pass (exit 0) before declaring the task done.

    line 124

≈ “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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

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        // M2

RIGHT:

import androidx.compose.material3.Button

Related 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.

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.