A (175)

(Tuis.) #1

82 CHAPTER 3: An Introduction to the Android Application Development Platform


Figure 3-9 shows three examples of the types of constant value files that you can place into this
values folder:


   dimens.xml: An XML file that defines dimension values, such as standard
heights or font sizes for your UI. You can then use these values across your app,
to ensure it is consistent.
 strings.xml: An XML file that defines text strings that are used in your
application. For example, you can place any screen titles, or the app name, here
and reference these in your code. If you need to change or refine these items in
the future, you simply do it in this one central location, rather than in your Java
code or XML markup.
 styles.xml: An XML file that defines UI design styles you can use across your
application. These styling constants will be applied to the UI elements that
reference the style constant definitions, allowing you to separate the look and
feel of your app from the physical layout and UI functionality. This makes your
app easier to refine, change, and enhance over time.

Some of the other types of value constant XML definition files you could create and place in your
Android project’s /res/values/ folder might include:


   arrays.xml: An XML file that defines a series of data value constants that
are intended to be utilized together (known as an array) in your application.
For example, this could be a list of icon files, a list of graphic layers, or a list of
options to display to the user.
 integers.xml: An XML file that defines constant numeric integer constant
values that will be used in your Java programming logic in your application.
 bool.xml: An XML file that defines Boolean constant values (true or false) that
will be used for the default (initial) setting for the states (like switches) in an
application. Examples of these would include states such as on or off, yes or no,
visible or hidden, and so on.
 colors.xml: An XML file that will define the color constant values to be used in
the app. These allow you to standardize the UI. For example, you could define
your app’s background color as a constant. Then, if you decide to tweak it later,
you need to do the tweak in only one place and the change is implemented
across your entire application. We will cover color theory and hexadecimal color
values in more detail in Chapter 9, which covers graphic design.

Notice that Android uses certain file naming conventions for the different types of XML files in the
/res/values/ folder, adding another level of complexity. It is important to note that you can also
create your own customized XML files and file names in this folder, so you are not limited to the
constant types that are discussed here. Next, let’s cover the folder names that Eclipse ADT did not
automatically create for you, and that you can optionally utilize to contain other asset types such as
animation, digital video, digital audio, and XML data.

Free download pdf