@@ -226,6 +226,32 @@ android:
226226 colors :
227227 # [optional] The package to export the Jetpack Compose color code to. Note: To export Jetpack Compose code, also `mainSrc` and `resourcePackage` above must be set
228228 composePackageName : " com.example"
229+ # [optional] Theme attributes configuration for generating attrs.xml and styles.xml
230+ themeAttributes :
231+ # Enable theme attributes export
232+ enabled : true
233+ # Path to attrs.xml (relative to mainRes)
234+ attrsFile : " ../../../values/attrs.xml"
235+ # Path to styles.xml for light mode (relative to mainRes)
236+ stylesFile : " ../../../values/styles.xml"
237+ # [optional] Path to styles-night.xml for dark mode (relative to mainRes)
238+ stylesNightFile : " ../../../values-night/styles.xml"
239+ # Theme name used in markers (e.g., "Theme.BaseTheme.inDrive")
240+ themeName : " Theme.BaseTheme.inDrive"
241+ # [optional] Custom marker start text. Default: "FIGMA COLORS MARKER START"
242+ markerStart : " FIGMA COLORS MARKER START"
243+ # [optional] Custom marker end text. Default: "FIGMA COLORS MARKER END"
244+ markerEnd : " FIGMA COLORS MARKER END"
245+ # [optional] Auto-create files with markers if missing. Default: false
246+ autoCreateMarkers : false
247+ # [optional] Name transformation settings
248+ nameTransform :
249+ # Target case style: camelCase, PascalCase, snake_case, etc. Default: PascalCase
250+ style : PascalCase
251+ # Prefix to add to attribute names. Default: "color"
252+ prefix : " color"
253+ # [optional] Prefixes to strip from color names before transformation
254+ stripPrefixes : ["extensions_", "information_", "statement_", "additional_"]
229255 # Parameters for exporting icons
230256 # Can be a single object (legacy format) or an array of objects (new format)
231257 # Legacy format (single icons configuration):
@@ -688,6 +714,156 @@ If `figmaFrameName` is not specified in an entry, it falls back to:
6887141. `common.images.figmaFrameName` (if defined)
6897152. `"Illustrations"` (default)
690716
717+ # # Android Theme Attributes
718+
719+ ExFig supports generating Android theme attributes (`attrs.xml` and `styles.xml`) that reference exported color
720+ resources. This is useful for creating theme-aware apps where colors are accessed via theme attributes rather than direct
721+ resource references.
722+
723+ # ## Overview
724+
725+ Theme attributes allow your app to reference colors like `?attr/colorBackgroundPrimary` instead of
726+ `@color/background_primary`. This enables :
727+
728+ - Theme switching at runtime
729+ - Centralized color management through themes
730+ - Separation between design tokens and theme-specific values
731+
732+ # ## Generated Output
733+
734+ **attrs.xml** (attribute declarations):
735+
736+ ` ` ` xml
737+ <resources>
738+ <!-- FIGMA COLORS MARKER START: Theme.BaseTheme.inDrive -->
739+ <attr name="colorBackgroundPrimary" format="color" />
740+ <attr name="colorBackgroundSecondary" format="color" />
741+ <attr name="colorTextPrimary" format="color" />
742+ <!-- FIGMA COLORS MARKER END: Theme.BaseTheme.inDrive -->
743+ </resources>
744+ ` ` `
745+
746+ **styles.xml** (theme values):
747+
748+ ` ` ` xml
749+ <resources>
750+ <style name="Theme.BaseTheme.inDrive" parent="Theme.MaterialComponents.DayNight">
751+ <!-- FIGMA COLORS MARKER START: Theme.BaseTheme.inDrive -->
752+ <item name="colorBackgroundPrimary">@color/background_primary</item>
753+ <item name="colorBackgroundSecondary">@color/background_secondary</item>
754+ <item name="colorTextPrimary">@color/text_primary</item>
755+ <!-- FIGMA COLORS MARKER END: Theme.BaseTheme.inDrive -->
756+ </style>
757+ </resources>
758+ ` ` `
759+
760+ # ## Configuration
761+
762+ ` ` ` yaml
763+ android:
764+ mainRes: "./main/res/figma/color/base"
765+ colors:
766+ themeAttributes:
767+ enabled: true
768+ attrsFile: "../../../values/attrs.xml"
769+ stylesFile: "../../../values/styles.xml"
770+ stylesNightFile: "../../../values-night/styles.xml"
771+ themeName: "Theme.BaseTheme.inDrive"
772+ markerStart: "FIGMA COLORS MARKER START"
773+ markerEnd: "FIGMA COLORS MARKER END"
774+ autoCreateMarkers: false
775+ nameTransform:
776+ style: PascalCase
777+ prefix: "color"
778+ stripPrefixes: ["extensions_", "information_", "statement_", "additional_"]
779+ ` ` `
780+
781+ # ## Configuration Options
782+
783+ | Field | Required | Default | Description |
784+ | ------------------- | -------- | ----------------------------- | ------------------------------------------ |
785+ | `enabled` | No | `false` | Enable theme attributes export |
786+ | `attrsFile` | Yes\* | — | Path to attrs.xml (relative to `mainRes`) |
787+ | `stylesFile` | Yes\* | — | Path to styles.xml (relative to `mainRes`) |
788+ | `stylesNightFile` | No | — | Path to styles-night.xml for dark mode |
789+ | `themeName` | Yes | — | Theme name used in markers |
790+ | `markerStart` | No | `"FIGMA COLORS MARKER START"` | Custom marker start text |
791+ | `markerEnd` | No | `"FIGMA COLORS MARKER END"` | Custom marker end text |
792+ | `autoCreateMarkers` | No | `false` | Auto-create files with markers if missing |
793+ | `nameTransform` | No | — | Name transformation settings |
794+
795+ \* Required when `enabled : true`
796+
797+ # ## Name Transformation
798+
799+ The `nameTransform` section controls how color names are converted to theme attribute names :
800+
801+ | Setting | Default | Description |
802+ | --------------- | ------------ | ----------------------------------------------- |
803+ | `style` | `PascalCase` | Target case style (camelCase, PascalCase, etc.) |
804+ | `prefix` | `"color"` | Prefix added to all attribute names |
805+ | `stripPrefixes` | `[]` | Prefixes to remove from color names |
806+
807+ **Examples:**
808+
809+ | Original Name | With `stripPrefixes : ["extensions_"]` | Result |
810+ | ----------------------------- | ------------------------------------- | ------------------------- |
811+ | `background_primary` | No strip | `colorBackgroundPrimary` |
812+ | `extensions_background_error` | Strips `extensions_` | `colorBackgroundError` |
813+ | `text_and_icon_primary` | No strip | `colorTextAndIconPrimary` |
814+
815+ # ## Marker-Based Updates
816+
817+ ExFig uses XML comment markers to update only specific sections of your files. This allows you to :
818+
819+ - Keep manual content outside markers
820+ - Have multiple themes in the same file (each with its own markers)
821+ - Safely run exports without losing custom code
822+
823+ **Marker format:**
824+
825+ ` ` ` xml
826+ <!-- MARKER_START: ThemeName -->
827+ ... generated content ...
828+ <!-- MARKER_END: ThemeName -->
829+ ` ` `
830+
831+ **Multiple themes in one file:**
832+
833+ ` ` ` xml
834+ <resources>
835+ <!-- FIGMA COLORS MARKER START: Theme.Light -->
836+ <attr name="colorBackground" format="color" />
837+ <!-- FIGMA COLORS MARKER END: Theme.Light -->
838+
839+ <!-- FIGMA COLORS MARKER START: Theme.Dark -->
840+ <attr name="colorBackground" format="color" />
841+ <!-- FIGMA COLORS MARKER END: Theme.Dark -->
842+ </resources>
843+ ` ` `
844+
845+ # ## Batch Mode
846+
847+ When running `exfig batch`, theme attributes from multiple configs can target the same `attrs.xml` and `styles.xml`
848+ files. ExFig automatically :
849+
850+ 1. Collects all theme attributes during batch processing
851+ 2. Groups by target file
852+ 3. Updates each theme's marker section separately
853+ 4. Writes merged results after all configs complete
854+
855+ This ensures no race conditions and proper merging of contributions from different configs.
856+
857+ # ## Error Handling
858+
859+ | Error | Cause | Solution |
860+ | -------------------- | -------------------------------------- | ----------------------------------------------- |
861+ | File not found | Target file doesn't exist | Create file manually or use `autoCreateMarkers` |
862+ | Marker not found | Markers missing in target file | Add markers manually or use `autoCreateMarkers` |
863+ | Markers out of order | End marker appears before start marker | Fix marker order in file |
864+
865+ When `autoCreateMarkers : true`, ExFig creates missing files with a minimal template containing the markers.
866+
691867# # CLI Options for Version Tracking
692868
693869In addition to the YAML configuration, you can control version tracking via CLI flags. Version tracking works for all
0 commit comments