Android resource naming convention

Anamika Tripathi
MindOrks
Published in
3 min readJul 16, 2018

As a developer, there is a good probability that you have used libraries to make code cleaner and easier to use. You have followed certain naming convention like camelCase for Java.

Have you ever done same for values like dimensions, strings? Probably, no. We end up creating lots of items in files & hard to find one, difficult to manage. Resources file names are written in lowercase_underscore. I’ll discuss few naming convention for android resources.

Layout

Layout files should match the name of the Android components that they are intended for but moving the top level component name to the beginning. For example, if we are creating a layout for the SignInActivity, the name of the layout file should be activity_sign_in.xml.

A slightly different case is when we are creating a layout that is going to be inflated by an Adapter, e.g to populate a ListView or Recyclerview. In this case, the name of the layout should start with item_.

Example of layout resource files

Strings

String names start with a prefix that identifies the section they belong to. We use <HOW>_<DESCRIPTION> for strings naming. <HOW> to indicate reason of the string will be used & description give any extra information.

For ex:

  • <string name="label_home">Home</string> : how = label & home is description of the string.
  • <string name="hint_user_name">Enter Your Name</string> : how = hint & user_name is the description of string.

Drawables

We use <WHAT>_<DESCRIPTION> for strings naming. <WHAT> is Button,Dialog,Divider,Icon, etc & description give any extra information.

Dimensions

Apps should only define a limited set of dimensions, which are constantly reused.

<WHAT>_<WHERE>_<SIZE> :

  • <WHAT> : It can be width(in dp), height (in dp), size (if width == height), margin(in dp), padding(in dp), elevation(in dp). text_size(in sp).
  • <WHERE>: It can be any specific item or remove this section if used throughout the application.
  • <SIZE>: It can be dp or sp.

That’s all! Even though this convention doesn’t cover all resource types, it does provide an easy to use solution for the most used ones. Feel free to add more conventions & give suggestion so that I can learn more from your experience.

Thanks for reading! Be sure to click claps below to recommend this article if you liked it.

You can connect with me on Github, Twitter, Linkedin :)

--

--

Anamika Tripathi
MindOrks

Android Developer @Zomato | Google Udacity Scholar | GSoC19 Mentor @Mifos | GSoC18 student @systers_org | GCI Mentor | Tech speaker