Android projects use XML in several ways: defining the project and components, building layouts, defining animations, creating menus and specifying resources (static and dynamic) for the project.
Introduction
In addition to Java code, Android projects (and their developers) have the ability to utilize XML to perform many standard tasks. Some XML usage is required, such as the definition of the projects and its components. Much of XML's usage is optional, making many common tasks easier. The Android XML schema is highly flexible and may be used in combination with code, exclusively, or not at all. Below is a list of common usage of XML:
- Manifest - definition of the project
- Layout - creation of partial or complete layouts for Activities, Dialogs, and Widgets
- Colors - Constant color values used throughout the project
- Style & Themes - application of custom standardized looks of Views
- Animations - Standardized animations that may be applied to Views.
- Drawables - Some specialized icons and graphics that may not be created wholely with an image editor. (StateDrawables, TranstionDrawables, Shapes and VectorGraphics)
- Menu - A resource used to aid in standardized menus for an Activity
- Integers, Strings, and Arrays - Constants used by the Application as resources.
AndroidManifest.xml
This file is a core component for every Android project. In order for nearly every component to work, it must be declared in the Manifest. The Manifest may affect everything from type of instancing to meta-data, even security restrictions. A comprehensive resource for the AndroidManifest.xml file exists at the Android Developers Dev Guide. Questions regarding the Android Manifest should use the android-manifest tag instead.
Android Layout XML
Android Layout may be partially or fully defined in XML to modularize presentation and limit code. The capabilities of Android Layout XML are quite extensive, allowing nearly every aspect of presentation to be managed in pure XML. Questions regarding layout should also use the android-layout tag.
Resources (Integers, Arrays, Strings, Colors, Styles, Themes, Menus)
One of the predominant uses of Android XML is to define resources that may be used by the entire application code base, similar to that of constants. Since so much of resource definition has been standardized throughout software development as a whole, XML provides a way to define these without having to manually generate much code that puts these to use. Before posting a question, it is best to make sure it is not covered by these documents:
- Application Resources
- Menu Developer Guide, Menu Reference & Action Bar Guide
- Styles & Themes Guide & Standard Styles & Themes
Drawables and Animations
Android allows you to define special drawables or animations via XML. The ability to dynamically generate graphics and animation can significantly reduce code and further separate presentation from implementation. Questions regarding either of these should also utilize the animation tag or drawable tag respectively.