Android's system works with so called 'drawables' for images. If we're adding drawables to our app, we need to create a drawable for each screen density and add it to the appropiate folder. For example, on devices with an Extra High screen density, icons will be loaded from the res/drawable-xhdpi folder.
When creating icons, we're usually creating icons for the Navigation Drawer, for Tabs, or for the Toolbar/Actionbar. All these icons have a size of 24dp (we don't use pixels, as the pixel size varies for all icons).
Instead of manually creating an icon for each resolution, we can use a tool to create a drawable, like Android Asset Studio.
Step by step guide to adding an icon
Perform these steps for each icon you'd like to add to your app.
- Open a tool to create an Android System Icon, like Android Asset Studio's ActionBar Icon tool.
If you're using Android Asset Studio, upload your own icon or select a predefined icon from the list. Set the padding to 0% (this will still result in some default padding, which is what we want) and select a theme/color for the icon. Usually we want black/grey icons.
- Export the icons from the tool, usually you'll get the icons in ~5 folders for each screen density.
- Now drag each icon from the export to the appropiate drawable folder in the project explorer of your project as shown below, make sure to do this for all screen densities.
- You can now access the drawable from within the app. You can refer to this drawable by using the R.drawable.drawablename reference. E.g. when the drawable is named ic_action_account_balance, you'll be using R.drawable.ic_action_account_balance as reference. Some templates only require the drawable name, and not the full reference, you can then simply use 'ic_action_account_balance' for the name.