By default, the Android manifest file resource editor is opened when you create a new Android project. If you have clicked away from this screen to check out the various project files, simply double-click the AndroidManifest.xml file within your new project to return to the Android manifest file resource editor (see Figure 1.3).
Editing an Android resource file in Eclipse.
The Android manifest file is the central configuration file for an Android application. The editor organizes the manifest information into a number of tabs:
► Manifest—This tab, shown in Figure 1.3, is used for general application-wide settings such as the package name and application version information (used for installation and upgrade purposes).
► Application—This tab is used to define application details such as the name and icon the application displays, as well as the "guts" of the application, such as what activities can be run (including the default launch DroidActivity) and other functionality and services that the application provides.
► Permissions—This tab is used to define the application's permissions. For example, if the application requires the ability to read the contacts from the phone, then it must register a Uses-Permission tag within the manifest, with the name android.permission.READ_CONTACTS.
► Instrumentation—This tab is used for unit testing, using the various instrumentation classes available within the Android SDK.
► AndroidManifest.xml—This tab provides a simple XML editor to edit the manifest file directly.
If you switch to the AndroidManifest.xml tab, your manifest file will look something like this:
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android"
<application android:icon="@drawable/icon" android:label="@string/app_name" > <activity android:name=".DroidActivity" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> <uses-sdk android:minSdkVersion="7" /> </manifest>
Because all Android resource files, including the Android manifest file, are simply XML files, you are always able to edit the raw resource files instead of using the resource editors. You can create a new Android XML file by clicking the Android XML creator icon, which looks like a file (with the letter a and a plus sign: on the Eclipse toolbar.
Did you Know?
Try It Yourself
Now let's edit the Android manifest file. One setting you're going to want to know about is the debuggable attribute. You will not be able to debug your application until you set this value, so follow these steps:
1. Open the AndroidManifest.xml file in the resource editor.
2. Navigate to the Application tab.
3. Pull down the drop-down for the debuggable attribute and choose true.
4. Save the manifest file.
If you switch to the AndroidManifest.xml tab and look through the XML, you will notice that the application tag now has the debuggable attribute: android:debuggable="true"
Editing Other Resource Files
Most Android application resources are stored under the /res subdirectory of the project. The following subdirectories are also available:
► /drawable-ldpi, /drawable-hdpi, /drawable-mdpi—These subdirectories store graphics and drawable resource files for different screen densities and resolutions. If you browse through these directories using the Eclipse Project Explorer, you will find the icon.png graphics file in each one; this is your application's icon. You'll learn more about the difference between these directories in Hour 20, "Developing for Different Devices."
► /layout—This subdirectory stores user interface layout files. Within this subdirectory you will find the main.xml screen layout file that defines the user interface for the default activity.
► /values—This subdirectory organizes the various types of resources, such as text strings, color values, and other primitive types. Here you find the strings.xml resource file, which contains all the resource strings used by the application.
If you double-click on any of resource files, the resource editor will launch.
Remember, you can always edit the XML directly.
Edit a String Resource
If you inspect the main.xml layout file of the project, you will notice that it displays a simple layout with a single TextView control. This user interface control simply displays a string. In this case, the string displayed is defined in the string resource called @string/hello.
To edit the string resource called @string/hello, using the string resource editor, follow these steps:
1. Open the strings.xml file in the resource editor.
2. Select the String called hello and note the name (hello) and value (Hello World, DroidActivity!) shown in the resource editor.
3. Within the Value field, change the text to Hello, Dave.
If you switch to the strings.xml tab and look through the raw XML, you will notice that two string elements are defined within a <resources> block:
<?xml version="i.0" encoding="utf-8"?> <resources>
<string name="fteiio">Hello, Dave</string> <string name="app_name">Droid #1</string> </resources>
The first is the string @string/hello. The second is @string/app_name, which contains the name label for the application. If you look at the Android manifest file ▲ again, you will see @string/app_name used in the application configuration.
We will talk much more about project resources in Hour 4, "Managing Application Resources." For now, let's move on to compiling and running the application.
Was this article helpful?