https://github.com/rikkaapps/materialthemebuilder
A gradle plugin that generates Material Design 3 theme for Android projects.
https://github.com/rikkaapps/materialthemebuilder
android gradle gradle-plugin material-design
Last synced: 4 months ago
JSON representation
A gradle plugin that generates Material Design 3 theme for Android projects.
- Host: GitHub
- URL: https://github.com/rikkaapps/materialthemebuilder
- Owner: RikkaApps
- License: mit
- Created: 2022-04-01T07:18:12.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2024-10-04T04:43:05.000Z (over 1 year ago)
- Last Synced: 2025-04-06T03:06:46.003Z (about 1 year ago)
- Topics: android, gradle, gradle-plugin, material-design
- Language: Java
- Homepage:
- Size: 152 KB
- Stars: 97
- Watchers: 7
- Forks: 16
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# MaterialThemeBuilderPlugin
Same as Google's [Material Theme Builder](https://material-foundation.github.io/material-theme-builder), but as a gradle plugin.
## Usage

Replace all the `` below with the version shows here.
1. Add gradle plugin
```groovy
// "old way"
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'dev.rikka.tools.materialthemebuilder:gradle-plugin:'
}
}
```
```groovy
// "new way"
plugins {
id 'dev.rikka.tools.materialthemebuilder' version ''
}
```
2. Use the plugin in Android application or library module
```groovy
plugins {
id('dev.rikka.tools.materialthemebuilder')
}
3. Config
```groovy
materialThemeBuilder {
// List of themes to generate
themes {
// Name of the theme
theme1 {
// Primary color, acts as the source color
primaryColor = "#3F51B5"
// Optional colors, override colors calculated from the source color
//secondaryColor = "#000000"
//tertiaryColor = "#000000"
//neutralColor = "#000000"
// Use dynamic colors on API 31+
dynamicColors = false
lightThemeFormat = "Theme.Material3.Light.%s"
lightThemeParent = "Theme.Material3.Light.Rikka"
darkThemeFormat = "Theme.Material3.Dark.%s"
darkThemeParent = "Theme.Material3.Dark.Rikka"
}
theme2 {
// ...
}
}
// List of extended colors
extendedColors {
// Name of the color
example {
color = "#000000"
// Harmonize generated color with primary color
harmonize = true
}
}
// Package name of your application, used in generated class
packageName = "com.example"
// Optional parts:
// Add Material Design 3 color tokens (such as palettePrimary100) in generated theme
// rikka.material:material >= 2.0.0 provides such attributes
// Enable this if your are using rikka.material:material
generatePalette = false
// Generate Material Design 3 color tokens attributes (such as palettePrimary100)
// When necessary, you can use this if your are not using rikka.material:material
generatePaletteAttributes = false
// Generate "textColorOnXxx" attributes such as "textColorOnPrimary", "textColorOnPrimaryHighEmphasis"
// and "textColorOnPrimaryMediumEmphasis"
generateTextColors = false
}
```
Harmonize color with dynamic themes:
```kotlin
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
HarmonizedColors.applyToContextIfAvailable(
context,
HarmonizedColorsOptions.Builder()
.setColorAttributeToHarmonizeWith(R.attr.colorPrimary)
.setColorAttributes(
HarmonizedColorAttributes.create(
HarmonizedColorAttributes.createMaterialDefaults().attributes
.plus(Harmonization.HARMONIZED_COLOR_ATTRIBUTES)
)
)
!!.build()
)
}
```