Android drawable assets can be either bitmaps files, such as PNG or JPG, or for more recent versions of Android can be defined in XML files. Your app's launcher icons are one example: PNG files that must be packaged in a variety of sizes to support different pixel densities. Android Studio can handle that sizing and packaging process for you.
- [Voiceover] Android Studio has tools that let you easily generate graphical assets. I'll show you how to use these using the same app as in a previous video, MemoryEater. But you can follow along with any Android app you like. When you create a brand new project in Android Studio, it has a launcher icon graphic. It's a picture of Andy the Android. But you'll want to place this graphic to properly brand your own application. The Android documentation has some guidelines.
Most importantly, there should be a square graphic and the source graphic should be at least 512 pixels square. It's also recommended that you include transparent backgrounds and that it not consist of a simple square. This allows each launcher icon on the screen to have its own unique profile. Now I've provided a simple graphic in the chapter 6 folder under 06_08, and its name is MemoryEater dot png.
It looks a little bit like PacMan, but it's my own graphic. And I'm going to turn that into the launcher icon for this app that appears on my device's home screen. In Android Studio, I'll go to the project window and I'll right-click on the project and choose new image asset. You can create launcher icons from Clipart, and if you want to do that you can click down here on the Clipart button, and you'll see a bunch of options there, or you can create it from text.
I'll type in me for memory eater, and I'll decide that's not as interesting or, as I'm going to do, you can start from your own image. I'll click the image option, and then click the browse button, then I'll go to my desktop to my exercise files, and I'll select my MemoryEater dot png file. Now my file has transparency, and you can see that in the way the source asset is displayed. But by default, the resulting icon will be in a rectangle with rounded corners.
And that's because this option, the shape option, has been set to square. You can change that to circle, vertical or horizontal rectangles, or as I'm going to do, to none. And that will retain my transparent background. There are also options to set the padding, to set the color of a background, and others. I'll click next, and that will result in previewing the resulting png files. Then I'll click finish, and that will override my existing launcher icon.
And once again, I'll get five different versions of the launcher icon for each of the standard pixel density buckets. Now, before I run this on my device I'll uninstall any existing versions. Depending on the state of the app on your device, this might or might not be necessary, but taking this step will ensure that you see the most recent launcher icon. Then I'll come back Android Studio, and I'll run the app. As before, if you see a problem, you can click okay to clear the app and then rebuild the app by selecting build and then clean, and then run it again.
And this time the app should run cleanly. Next, I'll go to my home screen, and then I'll go to my application list. I'll scroll until I find the MemoryEater app, I'll click and hold, and then drop the launcher icon onto the start screen, and there's my custom launcher icon. And I can click it to fire up the application. So that's the easiest way to take your own graphics and turn them into launcher icons or other images assets to include in your application.
- Installing Android Studio on Mac and Windows
- Creating Android Studio projects
- Setting up the development environment, including HAXM and the new Android emulator
- Importing existing code into Android Studio projects
- Exploring the interface, including the editor and project windows
- Managing project builds and dependencies
- Creating new Java classes
- Refactoring code
- Using templates
- Using breakpoints and watch expressions
- Updating apps with Instant Run
- Using Git for version control
Skill Level Beginner
Q: This course was updated on 04/27/2017. What changed?
A: New videos were added that highlight the new features introduced in Android Studio 2.3. In addition, the following topic was updated: update apps with Instant Run.