An open API service indexing awesome lists of open source software.

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.

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

![gradle-plugin](https://img.shields.io/maven-central/v/dev.rikka.tools.materialthemebuilder/dev.rikka.tools.materialthemebuilder.gradle.plugin?label=gradle-plugin)

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()
)
}
```