A (175)

(Tuis.) #1

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


As you can see in Figure 4-16, an XML menu definition uses a

parent tag to define an
Android Menu (class-based) object, and inside of that Menu object, Android uses child
tags to define MenuItem (class-based) objects. Inside of the child tags are parameters that
set the MenuItem object’s configuration data fields, for things such as a MenuItem object name
(android:id), MenuItem order (android:orderInCategory), MenuItem ActionBar display mode,
(android:showAsAction) and the MenuItem label (android:title).


As you can see, another convention in Android, as well as in Java, is that data field or parameter
names will use “CamelCase,” which uses internal capitalized letters, but start the variable (also
known as data fields, properties, or parameters) names with a lowercase letter. This helps in
readability, as you can see. An exception to this is Java Class names, which start with an uppercase
letter. We will get into all of that in detail in the next chapter.


Now it’s time to look at the most complicated XML file within the Android application, and the most
important one as well: the AndroidManifest.xml file, located in your /HelloUniverse “root” (top-most)
project folder. This Android Manifest XML file is used in the same exact way in 32-bit Android 4 and
64-bit Android 5.


This XML application definition file is the first XML file that the Android OS (runtime) looks at when
your app is launched by your user on their Android hardware device. It defines everything about your
application so that the Android OS knows exactly what it is dealing with.


The Android Manifest, as it is termed, specifies how many Activities, Services, and Providers are
to be used in the application, as well as defining more complex constructs, such as Intent Filters,
if they are needed by the application. You will be learning about all of these areas of the Android OS
during the course of this book.


The Android Manifest also defines more simple and basic things such as API support, versioning,
an app icon, name, and OS theme. These may be simpler to conceptualize, but they are no less
important to the overall app.


Figure 4-16. The /res/menu/main.xml file, with child tag and parameters inside of parent

tag

Free download pdf