material-components / material-components/material-components-android
[MaterialColors] Resolve attribute colors using Resources
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Java
- Sterne
- 17.4k
- Forks
- 3.2k
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beschreibung
I'm building a library that desaturates colors when Dark theme is enabled (as described in Material Docs)
Basically, I'm overriding getColor and getColorStateList in android.content.res.Resources, and them returning the requested color desaturated. But when it comes to material widgets, it doesn't work.
So, diving into material widgets, I noticed that the colors are retrieved calling MaterialColors.getColor that calls MaterialAttributes.resolveOrThrow, and after resolving the attributeId, the color is directly available in typedValue.data (line 71). But in this way, the call toResources is skipped and my desaturation methods will never be called.
My solution is to call ContextCompat.getColor(context, typedValue.resourceId) instead of typeValue.data at line 71 of MaterialAttributes.java.
I understand that this can cause some performance impact by retrieving the color another time, but I'm writing this library because a lot of application has dynamic primary and accent colors, and it's a pain to calculate manually the desaturated colors by hand and then add to night-values.
Or please let me know if the problem can be resolved in another way.
Here's the screenshot
not desaturated
desaturated
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne in MaterialAttributes.java bei Zeile 71 und verfolge den MaterialColors.getColor-Pfad durch MaterialAttributes.resolveOrThrow. Vergleiche den direkten typedValue.data-Lookup mit dem ContextCompat.getColor-Vorschlag des Issues und überprüfe anschließend, dass die Farben der Material-Widgets über die überschriebenen Resources-Methoden laufen und wie erwartet entsättigt werden.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- java
- Bereich
- mobile-dev
- Issue-Typ
- Bug
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 42/100