Skip to content

Why does colorPrimary not exist in values.xml? Inconsistent Handling of colorPrimary and colorOnPrimary Attributes Between Material 1.12.0 and 1.13.0-alpha #173

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
ronenfe opened this issue Apr 27, 2025 · 0 comments

Comments

@ronenfe
Copy link

ronenfe commented Apr 27, 2025

There is a discrepancy in how the colorPrimary and colorOnPrimary attributes are handled between Material Components 1.12.0 and 1.13.0-alpha.

In Material 1.12.0:

colorPrimary is pulled from appcompat theme if it’s not explicitly defined in the Material Components theme.

colorOnPrimary and all other attributes are correctly handled by Material Components and pulled from its theme attributes.

In Material 1.13.0-alpha:

colorPrimary does not exists in Material Components, and trying to access it using com.google.android.material.R.attr.colorPrimary results in an error. It seems Material Components no longer provides colorPrimary, and the fallback to appcompat does not happen.

colorOnPrimary works as expected, but the behavior of colorPrimary has changed significantly, breaking backward compatibility.

Steps to Reproduce:

Implement Material Components 1.12.0 in your project.

Access colorPrimary and colorOnPrimary as follows:

customColorScheme.primary = getThemeColor(
    this,
    com.google.android.material.R.attr.colorPrimary
)
customColorScheme.onPrimary = getThemeColor(
    this,
    com.google.android.material.R.attr.colorOnPrimary
)

In Material 1.12.0, colorPrimary will be pulled from appcompat if not explicitly defined, while colorOnPrimary will be correctly pulled from Material Components.

Switch to Material Components 1.13.0-alpha and try the same code.

colorPrimary will result in an error, as it’s not available in 1.13.0-alpha.

colorOnPrimary will still work.

Expected Behavior:

In both versions, colorPrimary should either be available in Material Components or should fall back to appcompat if not defined in the Material theme.

There should be no break in behavior when upgrading from 1.12.0 to 1.13.0-alpha regarding colorPrimary.

Actual Behavior:

In 1.12.0, colorPrimary falls back to appcompat.

In 1.13.0-alpha, colorPrimary is no longer available in Material Components, and trying to access it results in an error.

Possible Fix:

Ensure that colorPrimary is either consistently available in Material Components or explicitly falls back to appcompat to maintain compatibility.

Environment:

Material Components 1.12.0

Material Components 1.13.0-alpha

Android 11 and above

I'm not sure why colorPrimary attribute never existed in values.xml in all versions while all other attributes do exist.
Also colorError missing.

I can explicity fix it with android.R.attr. like

  customColorScheme.primary = getThemeColor(
                this,
                android.R.attr.colorPrimary            )
            customColorScheme.onPrimary = getThemeColor(
                this,
                com.google.android.material.R.attr.colorOnPrimary
            )

I'm not sure about the consequences.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant