A (175)

(Tuis.) #1

124 CHAPTER 4: Introduction to XML: Defining an Android App, Its Design, and Constants


There is also an android:label parameter inside the child tag that is also set to
@string/app_name, making this the same exact parameter as was used inside of the
tag, which is both a parent tag (to the tag) as well as a child tag (to the tag).


You are probably wondering what the usage difference is between these two parameters. The
app_name text string in the tag is applied underneath the app launcher icon, as that is
what labels the application.


The app_name text string in the tag is applied in the ActionBar, as that Activity (screen)
title, and if you have more than one Activity (UI or screen area) in your app, this Activity title could be
used to tell your users where they are in the app, or you can keep it as the app name for branding
purposes. It’s entirely your call.


This is a great example of how you can use a single XML constant value (in this case, it is a text
string value) in more than one area of your application, and for more than one purpose. This is
exactly why Android has set this modular asset and resource referencing up in this way, as when
leveraged optimally by a developer, it will allow a more efficient and effective optimization of
application resources by encouraging more modular and logical resource definition and usage. As
you can see in Figure 4-17, there is a third level of nesting underneath the tag where an


child tag is defined, which launches the application from the main (icon) screen of the
Android device. We will be getting into Intents and the IntentFilter class later on, in Chapter 7, when
we cover event handling and processing Intent objects.

To describe what the is doing here for you, so you don’t have to wonder for several
chapters, the child tag (we are now at five levels of nesting) defines an Android Action
Constant of MAIN, which refers to the Android MAIN screen, and the child tag defines
the category or “type” of action that should be taken (in this case, using the Android Category
Constant of LAUNCHER, which tells the Android OS to launch the application). Essentially this is
what tells the Android OS to launch your application when the user uses your app icon within their
OS. Next, let’s take a look at all this XML construction in a single view!


XML Application Structure: A Bird’s Eye View


Before we learn how to edit these XML files visually inside of Eclipse ADT, which we are going to
learn about in the next section of this chapter using the Eclipse Graphical Layout Editor (GLE), let’s
take a look at how all this XML that we’ve been looking at during this chapter fits together into the
larger XML structural picture.


I am only going to cover the GLE in detail in this book because it is an Absolute Beginners book.
I do not promote using the GLE in my Pro Android books, as an advanced developer should get used
to thinking in and writing XML and Java code directly, but you can use the GLE as a shortcut for
previewing some XML design work, including most UI design tasks, so that you do not have to use the
more time-consuming AVD emulator as you are designing your UI design-related XML markup. There
are some graphics features, such as blending modes and animation, that do not work in the GLE.


As you can see in Figure 4-17, as well as in the diagram in Figure 4-18, the AndroidManifest.xml file
is where everything starts from (XML or otherwise) in an Android application. This is very similar to an
index.html file, which will “bootstrap” or launch an HTML5 web site or an HTML5 application.

Free download pdf