Skip to content

Oncontainer colors created by a seed color which is the same as the primary color creates a brighter color then the default color. #174

@ronenfe

Description

@ronenfe
    @SuppressLint("RestrictedApi")
    fun updateColorScheme() {

        // Create a seed color (e.g., HCT color from ARGB value)
        var isDarkMode =
            resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK == Configuration.UI_MODE_NIGHT_YES
        val seedColorInt = themeColor // Hex color value
        val typedValue = TypedValue()
        val theme = this.theme
        theme.resolveAttribute(android.R.attr.colorPrimary, typedValue, true)
        val seedColorHct: Hct? = Hct.fromInt(typedValue.data)
        // Set contrast level (0.0 for default contrast)
        val contrastLevel = 0.0

        // Create a SchemeTonalSpot object based on the seed color
        val dynamicScheme =
            SchemeTonalSpot(seedColorHct, isDarkMode, contrastLevel)

        customColorScheme.onPrimaryContainer = dynamicScheme.onPrimaryContainer
        customColorScheme.onSecondaryContainer = dynamicScheme.onSecondaryContainer
        customColorScheme.onTertiaryContainer = dynamicScheme.onTertiaryContainer


        customColorScheme.onPrimaryContainer = getThemeColor(
            this,
            com.google.android.material.R.attr.colorOnPrimaryContainer
        )

        customColorScheme.onSecondaryContainer = getThemeColor(
            this,
            com.google.android.material.R.attr.colorOnSecondaryContainer
        )

        customColorScheme.onTertiaryContainer = getThemeColor(
            this,
            com.google.android.material.R.attr.colorOnTertiaryContainer
        )
    }

Compare the values here when the seed you use is the primary color. You will see the colors for the default theme is darker then the custom theme. It happens only when in day mode. Expected result is same color.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions