Resources available for Android app development
Anything we might say will surely sound Chinese to a customer-owner of an app project on which we are working − when we talk to him about the resources available on Android. However, these resources are a very important part of Android app development and defining them correctly is vital to accomplish a good app design. The app designer should know – precisely for this reason − what we mean by these resources… If it’s not the case, read on. We’ll start with the basics.
What are these resources?
Android resources are basically files or external data supporting our app’s operation. These files can be images, strings, colours, styles, etc. One of their main advantages is that they enable designers to work simultaneously with Android app developers.
While this does not guarantee fewer errors, the development time will be shorter if there is a rapport between both sides.
Adding a resource to an app is very easy: you only need to add the file to the required folder in the project. The system will automatically create a resource ID within the R class for each resource that we add.
We’ll find these resources in the folder called MyProyect/res. It contains the subdirectories that bring together the different kinds of resources that will be discussed below.
You might be interested | Where to Find an Android App Development Company
We will now see some more specific examples in case you are not yet sure about the use of these resources.
They can be used to render an app available in multiple languages. We can assign values to strings that change the app’s language according to the language set on a particular mobile device.
They can also be useful for adjusting the app when the device switches from a vertical position (portrait) to a horizontal one (landscape) and vice versa, thus becoming more practical and user-friendly.
Other uses: fitting in different screen sizes and densities (smartphones, phablets, tablets, etc.), adapting to different kinds of navigation, etc.
Kinds of resources for Android app development
Even though there are hundreds of blogs that have developed their own tables, we draw the following information from Android Developers to put at your disposal information coming from the most official source possible. This source contains all the information available on the different kinds of resources that you can use in Android app development. We suggest the following classification:
1. Animation Resources
Their purpose is to set default animations.
They are stored in the res/drawable/ folder under the R.drawable identifier. They support bitmap files (.png, .jpg or .gif), PNG files in Nine-patch (.9.png) format and XML files with graphics descriptors.
They can also be found in a folder called res/animator/ under ID R.anim and support XML files that modify an object’s properties over time.
2. Colour State List Resources
For determining a component’s colour depending on its state.
Stored in res/color/ and accessed through R.color.
3. Drawable Resources
For defining bitmap or XML graphics. They are stored in the res/drawable/ folder under the R.drawable identifier.
4. Layout Resources
For defining an app’s interfaces. They contain XML files and are stored in res/layout/ under ID R.layout.
5. Menu resources
For defining the contents of an app’s menus. They are stored in res/menu/ and accessed through R.menu.
6. String Resources
They contain XML files with data embedded in strings or in string arrays (including the string’s format and style). They can be sorted into strings.xml, colors.xml, dimens.xml, styles.xml or arrays.xml and are stored in res/values/ and include R.string, R.array, and R.plurals.
7. Style Resources
They define a number of attributes that can be applied to a view or an activity. Also used for defining an app’s style and design. They are stored in res/values and accessed through R.style.
8. Other types:
We’ll be defining values as being Boolean, integer, dimensions, colours and other arrangements.
They are stored in res/values/ but each of them is accessed through unique R subclasses (such as R.bool, R.integer, R.dimen, etc.).
And what about alternative resources?
Yes, Android app development resources also allow variations. By an alternative resource, we mean the variation of a resource that adjusts to a configuration feature available on a specific mobile device where the app is running.
What makes using alternative resources possible for us? Well, we should thank Google itself for compiling a list of qualifiers, which standardises the possible configurations available on Android devices. It’s a grammatical mechanism that dates from Android’s 4.3 version (API 21) and enables specifying a resource’s purpose, i.e. modify its main function:
A good example of its use is when specifying − with the mipmap/ resource − different variations for different kinds of screens. Each version will contain a qualifier for each screen variation. The app may then choose the variation that fits the terminal best.
As the experts from HermosaProgramación put it, “ipmap-hdpi will contain the variation of the ic_launcher.png resource for devices with high-density screens (~ 240dpi). This condition is specified by the hdpi qualifier”, as we’ll see in the following example.
Let’s also not forget that the image must be perfectly designed to fit specific sizes and densities. The images created must fit the corresponding qualifiers. Let’s see some of these qualifiers:
Qualifier or suffix: small
For small screens, like those displaying QVGA (320x426dps)
Qualifier or suffix: normal
For normal screens, like those displaying HTC Magic or the like (320x470dps)
Qualifier or suffix: large
Resources for large screens. Tablets are the clearest example of this kind of screens. (480x640dps)
Qualifier or suffix: ldpi
Low-density resources (between 100 and 120 dpi)
Qualifier or suffix: mdpi
Medium density (120 and 160 dpi)
Qualifier or suffix: hdpi
High density (between 160 and 260 dpi)
Qualifier or suffix: nodpi
For density-independent resources. This qualifier will not force the platform into scaling up resources.
Qualifier or suffix: long
For screens of any size and density, where the aspect ratio of both width and height is much higher than the screen’s basic configuration.
Qualifier or suffix: notlong
For screens where the aspect ratio is similar to the screen’s basic configuration.
Qualifier or suffix: v<api-level>
Allows identifying precisely which resources will be needed for an API’s specific version or for a higher version.
Qualifier or suffix: port
Indicates that these resources will be used for the screen’s portrait mode (or vertical mode).
Qualifier or suffix: land
Indicates that these resources will be used for the screen’s landscape mode (or horizontal mode).
Well, there is our article on how to use resources in Android development!