Android Programming The Big Nerd Ranch Guide, 3rd Edition

(Brent) #1
Defining a menu in XML

253

Using Android Asset Studio


In the android:icon attribute, the value @android:drawable/ic_menu_add references a system icon. A
system icon is one that is found on the device rather than in your project’s resources.


In a prototype, referencing a system icon works fine. However, in an app that will be released, it is
better to be sure of what your user will see instead of leaving it up to each device. System icons can
change drastically across devices and OS versions, and some devices might have system icons that do
not fit with the rest of your app’s design.


One alternative is to create your own icons from scratch. You will need to prepare versions for each
screen density and possibly for other device configurations. For more information, visit Android’s Icon
Design Guidelines at developer.android.com/design/style/iconography.html.


A second alternative is to find system icons that meet your app’s needs and copy them directly into
your project’s drawable resources.


System icons can be found in your Android SDK directory. On a Mac, this is typically /Users/user/
Library/Android/sdk. On Windows, the default location is \Users\user\sdk. You can also verify
your SDK location by opening the project structure window and selecting the SDK Location option.


In your SDK directory, you will find Android’s resources, including ic_menu_add. These resources
are found in /platforms/android-25/data/res, where 25 represents the API level of the Android
version.


The third and easiest alternative is to use the Android Asset Studio, which is included in Android
Studio. The Asset Studio allows you to create and customize an image to use in the toolbar.


Right-click on your drawable directory in the project tool window and select New → Image Asset to
bring up the Asset Studio (Figure 13.5).


Here, you can generate a few types of icons. In the Icon Type field, choose Action Bar and Tab Icons.
Next, name your asset ic_menu_add and set the Asset Type option to Clip Art. Update the Theme to use
HOLO_DARK. Since your toolbar uses a dark theme, your image should appear as a light color. These
changes are shown in Figure 13.5; note that while we are also showing the clip art you are about to
select, your screen will feature the adorable Android logo.


http://www.ebook3000.com

Free download pdf