Code Monkey home page Code Monkey logo

materialthemebuilder's Introduction

MaterialThemeBuilderPlugin

Same as Google's Material Theme Builder, but as a gradle plugin.

Usage

gradle-plugin

Replace all the <version> below with the version shows here.

  1. Add gradle plugin

    // "old way"
    buildscript {
        repositories {
            mavenCentral()
        }
        dependencies {
            classpath 'dev.rikka.tools.materialthemebuilder:gradle-plugin:<version>'
        }
    }
    // "new way"
    plugins {
        id 'dev.rikka.tools.materialthemebuilder' version '<version>'
    }
  2. Use the plugin in Android application or library module

    plugins {
        id('dev.rikka.tools.materialthemebuilder')
    }
    
  3. Config

    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:

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

materialthemebuilder's People

Contributors

rikkaw avatar kr328 avatar yujincheng08 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.