A (175)

(Tuis.) #1
CHAPTER 4: Introduction to XML: Defining an Android App, Its Design, and Constants 125

As you just saw in the previous section of this chapter, the styles.xml file is accessed using the
android:theme parameter, set equal to @styles/AppTheme, and the activity_main.xml and main.
xml files are accessed through a MainActivity.java reference, which is located inside of the
tag, using an android:name parameter.


These XML UI and menu definitions are accessed through Java methods, which we will be looking at
in the next chapter. These methods serve to “inflate” these XML definitions into Java objects, and so
I include them in this graphic so that you can see how all of this XML markup affects and references
each other.


The AndroidManifest also directly accesses the strings.xml file in both the and


tags, using the android:label=“@string/app_name” parameter, which we learned does
different things when used inside of different XML tags.

The activity_main.xml UI design layout XML definition accesses the dimens.xml file to get the app’s
screen dimensions as well as the strings.xml file to get text string constant values to display the
Hello Universe message on the application’s primary Activity display screen.


The /res/values/styles.xml file references the styles.xml files located in your alternate resource
folders, named /res/values-v11 and /res/values-v14, to set the OS theme preferences for your
application. This depends upon if the end-user is using Version 3.x, Version 4.x, or legacy (earlier)
versions of the Android OS, such as 1.6 or 2.3.


It is important to note that this diagram only includes XML to XML referencing, and not XML to new
media assets referencing, most of which would exist underneath the activity_main.xml UI definition
in res/layout.


Next let’s take a look at the Eclipse ADT GLE, in case you have been wondering what that Graphical
Layout tab at the bottom of the Eclipse ADT central editing page does whenever you are working
on XML definition files that refer to UI design layouts, such as the activity_main.xml file does. I am
including this in the XML chapter to give you an early preview of this feature as well as an overview
of what it does, and how it can help the Absolute Beginner to quickly develop UI designs for their
Android applications.


Using the Eclipse Graphical Layout XML Editor


You may have noticed the Graphical Layout tab, located at the bottom-left of the Eclipse central
editing pane, when you were taking a look at the UI design XML definition at the beginning of the
chapter in Figure 4-1.


Figure 4-18. The HelloUniverse initial XML structure from the AndroidManifest.xml file on down the hierarchy

Free download pdf