Density-independent Pixels
Android Studio includes a tool called Image Asset Studio that helps you generate your own app
icons from
material icons,
custom images, and text strings. It generates a set of icons at the appropriate resolution
for each generalized screen
density that your app supports.
Image Asset Studio places the newly generated icons in density-specific folders under the
res/
directory in your project. At runtime, Android uses the appropriate
resource based on the screen density of the device your app is running on.
Image Asset Studio helps you generate the following icon types:
Image Asset Studio helps you create various types of icons at different densities and shows you exactly where they'll be placed in your project. It includes tools for adjusting your icons and adding backdrops, all while displaying the result in a preview pane, so they appear exactly as you intended. These tools can dramatically streamline the icon design and import process. The following sections describe the icon types that you can create and the image and text inputs that you can use.
A launcher icon is a graphic that represents your app to users. It can:
Image Asset Studio automatically creates separate icons for the recommended generalized screen
densities, including mdpi, hdpi, xhdpi, xxhdpi, and xxxhdpi. This ensures that your icon displays
well on a variety of screens and devices. It places the icons in the proper locations in the
res/mipmap-density/
directories. It also creates a 512 x 512 pixel image
that's appropriate for the Google Play Store.
We recommend that you use the material design style for launcher icons, even if you support older Android versions.
See Launcher Icons and Product Icons - Material Design for more information.
Action Bar icons are graphical elements placed in the Action Bar and that represent individual action items. See Adding and Handling Actions, App Bar - Material Design, and Action Bar Design for more information.
Tab icons are graphical elements used to represent individual tabs in a multi-tab interface. Each tab icon has two states: unselected and selected. See Creating Swipe Views with Tabs and Tabs - Material Design for more information.
Image Asset Studio automatically creates separate icons for the recommended generalized
screen densities, including mdpi, hdpi, xhdpi, and xxhdpi. It places the icons in the proper
locations in the res/drawable-density/
directories.
We recommend that you use the material design style for action bar
and tab icons, even if you support older Android versions. Use appcompat
and other
support libraries
to deliver your material design UI to older platform versions.
As an alternative to Image Asset Studio, you can use Vector Asset Studio to create action bar and tab icons. Vector drawables are appropriate for simple icons and can reduce the size of your APK.
A notification is a message that you can display to the user outside of the normal UI of your app. When you tell the system to issue a notification, it first appears as an icon in the notification area. To see the details of the notification, the user opens the notification drawer. Both the notification area and the notification drawer are system-controlled areas that the user can view at any time.
Image Asset Studio automatically creates separate icons for the recommended generalized
screen densities, including mdpi, hdpi, xhdpi, and xxhdpi. It places the icons in the proper
locations in the res/drawable-density/
directories:
res/drawable-density/
directories.res/drawable-density-v9/
directories.res/drawable-density-v11/
directories.If your app supports Android 2.3 to 2.3.7 (API level 9 to 10), Image Asset Studio generates a gray version of your icon. Later Android versions use the white icon that Image Asset Studio generates.
See Notifications; Notifications Material Design; Notifications, Android 5.0 Changes; Notifications, Android 4.4 and Lower; and Status Bar Icons, Android 3.0 and Lower for more information.
Image Asset Studio makes it easy for you to import Google material icons in PNG form: simply select an icon from a dialog. For more information, see Material Icons.
You can import your own images and adjust them for the icon type. Image Asset Studio supports the following file types: PNG (preferred), JPG (acceptable), and GIF (discouraged).
Image Asset Studio lets you type a text string in a variety of fonts, and places it on an icon. It converts the text-based icon into PNG files for different densities. You can use the fonts that are installed on your computer.
To start Image Asset Studio, follow these steps:
Alternatively, right-click the res folder and select New > Image Asset.
Some other project views and folders have this menu item as well.
Image Asset Studio appears.
After you open Image Asset Studio, you can add a launcher icon by following these steps:
In the Select Icon dialog, select a material icon and then click OK.
The icon appears in the Source Asset area on the right side, and in the preview area at the bottom of the wizard.
Image Asset Studio places the icon within a transparent square so there's some padding on the edges. The padding provides adequate space for the standard drop-shadow icon effect.
The Output Directories area displays the images and the folders where they will appear in Project Files view of the Project window.
Image Asset Studio adds the images to the mipmap folders for the different densities.
After you open Image Asset Studio, you can add an action bar or tab icon by following these steps:
In the Select Icon dialog, select a material icon and then click OK.
The icon appears in the Source Asset area on the right side, and in the preview area at the bottom of the wizard.
Image Asset Studio creates the icon within a transparent square so there's some padding on the edges. The padding provides adequate space for the standard drop-shadow icon effect.
The Output Directories area displays the images and the folders where they will appear in Project Files view of the Project window.
Image Asset Studio adds the images in the drawable folders for the different densities.
After you open Image Asset Studio, you can add a notification icon by following these steps:
In the Select Icon dialog, select a material icon and then click OK.
The icon appears in the Source Asset area on the right side, and in the preview area at the bottom of the wizard.
Image Asset Studio creates the icon within a transparent square so there's some padding on the edges. The padding provides adequate space for the standard drop-shadow icon effect.
The Output Directories area displays the images and the folders where they will appear in Project Files view of the Project window.
Image Asset Studio adds the images in the drawable folders for the different densities and versions.
You can normally refer to an image resource in a generic way in your code, and when your app runs, the corresponding image displays automatically depending on the device:
@drawable
in XML code or
Drawable
in Java code. For example, the following layout XML code displays the drawable in an ImageView:
<ImageView android:layout_height="wrap_content" android:layout_width="wrap_content" android:src="@drawable/myimage" />
The following Java code retrieves the image as a
Drawable
:
Resources res =getResources()
; Drawable drawable = res.getDrawable
(R.drawable.myimage);
The getResources()
method resides in the Context
class, which applies to UI objects, such as
activities, fragments, layouts, views, and so on.
app:srcCompat
statement. For example:<ImageView android:layout_height="wrap_content" android:layout_width="wrap_content" app:srcCompat="@drawable/myimage" />
You can access image resources from the main thread only.
After you have an image resource in the res/
directory of your project, you can
reference it from your Java code or your XML layout using its resource ID.
The following Java code sets an
ImageView to use
the drawable/myimage.png
resource:
ImageView imageView = (ImageView) findViewById(R.id.myimageview); imageView.setImageResource(R.drawable.myimage);
See Accessing Resources for more information.
For launcher icons, the AndroidManifest.xml
file must reference
the mipmap/
location. Image Asset Studio adds this code automatically.
The following manifest file code references the
ic_launcher
icon in the mipmap/
directory:
<application android:name="ApplicationTitle" android:label="@string/app_label" android:icon="@mipmap/ic_launcher" >
To remove an icon from a project:
This folder contains the icon in different densities.
Alternatively, select Edit > Delete. Or right-click the file and select Delete.
The Safe Delete dialog appears.
Android Studio deletes the files from the project and the drive. However, if you chose to search for places in the project where the files are used and some usages are found, you can view them and decide whether to delete them. You must delete or replace these references to be able to successfully compile your project.
Android Studio removes any generated image files corresponding to the deleted image resource. It removes them from the project and the drive.
Android Studio highlights these errors in your code. When you've removed all references from your code, you can successfully build your project again.