Sams Teach Yourself Java™ in 24 Hours (Covering Java 7 and Android)

(singke) #1
ptg7068951

358 HOUR 24:Writing Android Apps

Files can be added to resources using drag and drop. Open the temporary
folder containing the five files, select them, and drag them to the drawable
folder in Package Explorer.
Now that the project has a new icon, you can set it as the app’s icon and
get rid of the errors noted in Package Explorer. This will be handled by
editing AndroidManifest.xml.

Configuring the App’s Manifest File
The primaryconfiguration tool in an Android app is a file called
AndroidManifest.xmlin the main app folder. All XMLfiles utilized by an
app can be edited manually or by using the built-in editor in Eclipse. The
latter is easier and less error prone. Unless you’re extremely comfortable
editing XML, you should stick to the editor until you’ve gained more expe-
rience as an Android programmer.
To choose the proper icon for the app, do the following:


  1. Double-click AndroidManifest.xmlin Package Explorer. The file
    opens for editing in the main Eclipse window using the built-in editor.

  2. Several tabs run along the bottom edge of the editor. Click the
    Application tab to see settings related to the app (see Figure 24.12).


CAUTION
Resources are identified in an app
using an ID formed from their file-
name with the extension removed.
appicon.pnghas the ID appicon,
browser.pnghas the ID browser,
and so on. No two resources can
have the same ID (with the excep-
tion of the same graphic being
stored at different resolutions in
the three drawable-*dpifolders,
because they count as a single
resource).
If two resources have the same
name without the extension,such
asappicon.pngand
appicon.gif, Eclipse will flag the
error and the app won’t compile.
Resources also must have names
that contain only lowercase let-
ters,numbers,underscores (_),
and periods (.). The files in this
project follow these rules.


FIGURE 24.12
Editing the app’s
AndroidManifest.xmlfile.
Free download pdf