The res/values folder is used to store the values for the resources that are used in many Android projects to include features of color, styles, dimensions etc.
Below explained are few basic files, contained in the res/values folder:
- colors.xml: The colors.xml is an XML file which is used to store the colors for the resources.
An Android project contains 3 essential colours namely:
These colors are used in some predefined resources of the android studio as well. These colors as needed to be set opaque otherwise it could result in some exceptions to arise.
Below mentioned is the implementation of colors.xml resource:
Note: It is also possible to define different user based colours for different types of resources.
- dimens.xml: The dimens.xml is used for defining the dimensions for different widgets to be included in the Android project. It is a good coding practice to use dimens.xml to define a dimension rather than just writing the dimension in the resource, due to the fact that if ever any need arises to change the dimension, instead of making a change to all, only the dimens.xml can be changed once and the change is reflected in all.
Below mentioned is the implementation of dimens.xml resource:
<!-- Default screen margins, per the Android Design guidelines. -->
It is also possible to apply user-defined dimensions.
Note: Always remember the difference in using dp or sp. Generally use sp for font size and dp for others.
- strings.xml: One of the most important as well as widely used values file is the strings.xml due to its applicability in the Android project. Basic function of the strings.xml is to define the strings in one file so that it is easy to use same string in different positions in the android project plus it makes the project looks less messy.
We can also define an array in this file as well.
Below mentioned is the implementation of strings.xml resource:
>Open navigation drawer</string>
>Close navigation drawer</string>
>Hello blank fragment</string>
Android studio gives a warning in layout xmls if a string is used in that file, thus it is a good practice to store all hardcoded strings in strings.xml file.
- styles.xml: Another important file in the values folder is the styles.xml where all the themes of the Android project are defined. The base theme is given by default having the option to customize or make changes to the customized theme as well. Every theme has a parent attribute which defines the base of the theme. There are a lot of options to choose from depending on the need of the Android project.
Below mentioned is the implementation of styles.xml resource:
<!-- Base application theme. -->
<!-- Customize your theme here. -->
If any feature used in the files in values folder does not match with the minimum SDK version of the user, then android studio gives the option to define a separate file with the same name but for different API level. For eg., styles and styles(v21)[for API levels of 21 and above].
Attention reader! Don’t stop learning now. Get hold of all the important Java and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.
- Android Project folder Structure
- Assets Folder in Android
- How to rename all files of a folder using Java?
- Android | AdMob Banner Ads for Android Studio
- Android | Android Application File Structure
- Android | AdMob Interstitial Ads for Android Studio
- Android | How to Create/Start a New Project in Android Studio?
- Android | Running your first Android app
- Android | How to add Radio Buttons in an Android Application?
- Android | How to Request permissions in Android Application?
- Difference between Android 1.1 and Android 4.0.1
- Difference between Android 1.1 and Android 2.3.4
- Difference between Android 1.0 and Android 1.1
- Difference between Android 1.0 and Android 7.1
- Difference between Android 1.0 and Android 2.3
- Difference between Android 1.0 and Android 2.2
- Difference between Android 1.0 and Android 1.6
- Difference between Android 1.0 and Android 2.1
- Difference between Android 1.0 and Android 2.0.1
- Difference between Android 1.0 and Android 2.0
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.