2.2 Resource Files

Before ending the chapter, we ought to understand some of the other files laying around in the res folder. These are the resource files of our project, and Android resource files are split into these sub-categories:

  1. Drawable contains images and icons for app in the phone’s home screen.

  2. Font contains custom font files

  3. Layout contains XML files for all the layouts in the project

  4. Mipmap contains icon images

  5. Raw contains audio and video media

  6. Values contains reusable values for colors, dimens, strings, and styles

For the most part, these resource files will remain empty until you start populating them with information, and it is generally good practice to move resources into the resource file if that resource going to be used multiple times. Along the same line, it’s good practice to move commonly used values into the resource files so that if the design of the app changes, you won’t have to go through every XML and class file to change the values.

For example, in order to avoid having to remember specific color codes, you can specify them in the colors.xml file. Now the color can be referenced by its string name.

  <color name="colorPrimary">#008577</color>
  <color name="colorPrimaryDark">#00574B</color>
  <color name="colorAccent">#D81B60</color>

You would refer to the colors in the XML file like so:


This way, if the designer decides to change up the color scheme of the app, you would only have to change three values.

Last updated