-
Notifications
You must be signed in to change notification settings - Fork 3k
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
[colorSurface] Bug: colorSurface value gets a different value in practice #1133
Comments
I think you are seeing the elevation overlay on top of your color while in dark theme. |
I choose a color, and I expect it to show this color. A bug. |
I have the same problem. Any updates on this? |
See https://stackoverflow.com/a/60803916/2153926 for some more discussion. This is intentional due to the Elevation Overlays that help communicate the elevation hierarchy of a UI in dark theme, since shadows are much less effective in a dark theme app: https://material.io/develop/android/theming/dark If you have specific colors and want to disable the overlays, you can add the following to your theme:
|
I understand what you mean, but read what @AndroidDeveloperLB said. I have the same problem. This is definitely a bug. Let's say that I have two screens with CardViews in them. The material CardView should inherit the ?colorSurface attribute from the app theme to adapt its background color. The problem here is, that on screen A the correct ?colorSurface from the theme is taken, and on screen B, some automatic overlay is put on the CardView. |
As long as both Activities have the same theme, or rely on the global app theme with no overrides, then I don't see any reason why 2 |
The point is that there is no way to predict which color we will get. Suppose that I want to have color X when the MaterialCardView is in normal state, how can I achieve it without ruining everything that's related to how things work (meaning setting elevationOverlayEnabled to false) ? |
The purpose of the elevation overlay is to change the color of the card view in its normal state, so the only real way is set elevationOverlayEnabled to false. Also, the overlay will only be applied to the card if the card's background color matches the theme's If you want to disable elevation overlays for all cards and no other components, you could do the following:
Or if you want to disable the elevation overlay for one just card, you can set the following on that card:
|
Another point to mention here is, that we define separate background and surface colors in our theme, but yet the surface color gets an overlay, resulting in duplicate brightening of the surface. To counter this, you would have to set the surface color of your theme to be the background color. Not really intuitive. |
By default, the background and surface colors that come with our Material themes are the same hex values. I agree that's not very intuitive. But it sounds like if you are already setting the surface color to a lighter hex value in your dark theme, then you don't really want the elevation overlay functionality - because that's exactly what that functionality is supposed to do for you. And it's dynamic based on elevation, as opposed to one hardcoded surface color. |
Again, how can I make sure the color will be the way the designer wanted, but without changing anything in the styles and how the cards behave? |
As I've already said before, the sole purpose of the elevation overlays is to change the color of the background in dark mode. If you want an exact hex color to appear, you need to disable the elevation overlays. |
Without disabling it. |
I'm not really sure what answer you are looking for. The default behavior is to add an overlay on elevated dark theme surfaces. So what you are asking is equivalent to "how can I do something without doing anything". What's the reason you don't want to disable the overlay if you don't want this overlay? |
After the addition of the "overlay elevated dark theme there is a color. |
Description: Full description of issue here
Just use this color for example #ff3c454c , take a screenshot, and check the real color you got.
Expected behavior: Screenshots and/or description of expected behavior
To see the exact value: #ff3c454c
See links at the bottom for video.
Source code: The code snippet which is causing this issue. Please consider attaching a minimal sample app that reproduces the issue.
See links at the bottom
Android API version: Android API version here
29
Material Library version: Material Android Library version you are using here (e.g., 1.1.0-alpha07)
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.android.material:material:1.2.0-alpha05'
implementation 'androidx.cardview:cardview:1.0.0'
Device: Device on which the bug was encountered here
Emulator
Also wrote about this here:
https://issuetracker.google.com/issues/152120291
https://stackoverflow.com/q/60800857/878126
The text was updated successfully, but these errors were encountered: