Providing an Icon for an Application

The <application> tag attribute called android:icon is a Drawable resource representing the application. In the Droid1 project, you set the application icon to the Drawable resource as follows:

<application android:icon="@drawable/icon">

Although you will place just a single icon reference in the <application> tag attribute android:icon, you will need to create three different icons. These will represent the three default icons for low pixel density screens (ldpi), high pixel density screens (hdpi), and medium pixel density screens (mdpi). The Android system will automatically choose the appropriate graphic based upon the capabilities of the device the application is running on. You will learn more about this topic in Hour 20, "Developing for Different Devices." For now, you can just create a single graphic and then resize it for the three different resolutions.

To make your own custom application icons, perform the following steps:

1. Design a 48x48 pixel graphic with your favorite graphics program. This is the icon for medium pixel density screens.

2. Save the graphic in PNG format, using the filename myicon.png.

3. Add the graphic file as a Drawable resource to your application, in the /res/drawable-mdpi directory.

4. Repeat steps 1-3, but resize the graphic to 72x72 pixels and place it in the /res/drawable-hdpi directory. This is the icon for high pixel density screens.

5. Repeat steps 1-3, but resize the graphic to 36x36 pixels and place it in the /res/drawable-ldpi directory. This is the icon for low pixel density screens.

6. Set the android:icon property to the resource name of your new icon, @drawable/myicon. This will pick one of the three graphics you created based on the pixel density of the handset (or emulator) that the application is running on.

The end result will be the same graphic found in three differently sized files in three different resource directories. Typically, a graphic may be further optimized for each resolution.

0 0

Post a comment