First up, let’s define the lint issue describing the problem we are looking for in our source code:

The issue is self-explanatory, so let’s look at the detector class ( MissingNightColorDetector ) that we have already bonded this issue with.

In Android, colors resources are defined under the values folder in a colors.xml file. Since we are looking for issues inside XML files, we’ll use the ResourceXmlDetector which defines how an XML file is parsed. It might help to understand the XML markup before proceeding. You can read about it here.

Each color is an XML Element

In Part 1, when we were looking for hardcoded colors, we looked at XML attributes. For parsing the colors.xml file (located inside the values folder), we need to look at XML Elements. We simply can’t declare support for the name attribute as that will also match other resources like String Resources, Style Resources, etc. Hence we declare support for the “color” element (see: getApplicableElements ) and then look at the name attribute inside the “color” element.

visitElement is then called for each XML element that the detector has mentioned it wants to analyze. Here, we extract out the color name (and NOT its value) and store it in a list representing the configuration of the values folder (regular/night). Finally when project inspection is complete ( afterCheckEachProject ), we report an issue for every color that exists in the regular value folder but not in the night variant folder.

Finally, update the registry to include the new check:

Run the lint check as usual and we should see new lint errors appear in the project (if there are missing night variant color resources).