Creating and Using Resource Files in Android Studio

Heather Gallop
5 min readFeb 21, 2018

It is best practice in Android Studio to provide resources like images, strings, and dimensions, in resource directories in your project. Getting in this habit will prepare you for providing alternative resources for specific device configurations and make it easier to add localization options to your project later. Not to mention the ease of use you will experience as you make changes to your app. When you provide them separately, Android uses the appropriate resource in all the places where you call a reference to the file. When you create a new project, some of these files and directories will be provided for you and you will have to create some on your own.

Be mindful of the names you give to files that you intend to add. Android only supports resource files with uppercase and lowercase letters, numbers, and the underscore symbol.

Sample file tree from Android Studio

Drawable:

The drawable folder holds all the images for your project. As a precaution, be sure to choose images of appropriate size and resolution. Images too large or with high resolution can cause your app to crash, so choose carefully. Android currently supports BMP, GIF, JPG, PNG, and WebP image formats. If the drawables folder is absent from your project, you can create it:

  • Right-click the res folder
  • Choose New
  • Choose Android Resource Directory
  • Name the directory drawable
  • In the Available Qualifiers Section add drawable
  • Click ok

Refer to drawable resources in your XML files by calling:

  • “@drawable/filename”

Font:

The font folder holds any custom font files you wish to use. Android currently supports ttf, otf, ttc, and xml font files. To create a font folder in your project:

  • Right-click the res folder
  • Choose New
  • Choose Android Resource Directory
  • Name the directory font
  • Click ok

Refer to font resources in your XML files by calling:

  • “@font/filename”

Layout:

The layout folder holds all the XML layout files for your projects. To create a new layout file in your project:

  • Right click on the layout folder
  • Choose New
  • Choose Layout Resource File
  • Name your file
  • Choose your Root Element
  • Click ok

Refer to layout resources in your Java files by calling:

  • R.layout.activity_name

Mipmap:

The mipmap folder holds the icon image for your apps launcher. These should be only as large as necessary to support the devices you want to target for your app. If mipmap is absent from your project, you can add it:

  • Right-click the res folder
  • Choose New
  • Choose Android Resource Directory
  • Name the directory mipmap
  • In the Resource Types Section add mipmap
  • Click ok

Any icon you choose to use as mipmap should be named ic_launcher and Android Studio will use the icon you provided.

Raw:

The raw folder holds media files such as video and audio. Android currently supports 3gp, mp4, m4a, aac, and ts audio file formats. Video file formats supported are 3gp, mp4, webm, and mkv. To create a raw folder:

  • Right-click the res folder
  • Choose New
  • Choose Android Resource Directory
  • Name the directory raw
  • In the Resource Types Section add raw
  • Click ok

Refer to raw resources in your Java files by calling:

  • R.raw.name

Values:

Sample values folder expanded

The colors file holds the hex codes for each color your would like to use in your app. You can add new colors by adding a new color element, giving it a name, and adding the desired color’s hex code. Android Studio provides a tiny preview of the color in the margin of the file.

Sample of colors.xml file

Refer to color resources in your XML files by calling:

  • “@color/colorname”

The dimen file holds all the “measurements” for your layouts. You can create new dimensions by adding a new dimen element, giving it a name, and adding your desired dimension in sp for text and dp for everything else.

Sample of dimen.xml file

Refer to dimen resources in your XML files by calling:

  • “@dimen/dimenname”

The strings file holds all of the text you would like to display to the user. You create strings by adding a new string element, giving it a name, and adding the text you would like to display (with no quotes).

Sample of strings.xml file

Refer to string resources in your XML files by calling:

  • “@string/stringname”

The styles file holds information about common attributes you will use throughout your app. If you chose to create a project with an activity, Android Studio will provide a default theme in styles. You can also create your own custom styles to provide common attributes across views.

Sample styles.xml file

Refer to style resources in your XML files by calling:

  • “@style/stylename” or
  • “@style/stylename.subclassname”

To create any of the files listed above in your values folder:

  • Right click on the values folder
  • Choose New
  • Choose Values Resource File
  • Name your file according to the resource you want to provide
  • Click ok

I hope this overview helps demystify the process of adding and using resources in Android Studio. Aligning with best practices early can prevent bad habits from forming, saving you from frustration later.

Happy Coding!

--

--