O'Reilly logo

Learning Android by Marko Gargenta

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Adding Color and Graphics

Our application works well, but it’s a bit dull looking. A little bit of color and some graphics could go a long way. Android offers a lot of support to make your application snazzy. We’re going to see some basics here.

Adding Images

For starters, we want to add a background to our screen. This background is going to be some kind of graphics file. In Android, most images go to a resource folder called drawable. You may notice that you already have three folders with this name:

  • /res/drawable-hdpi for devices with high-density screens

  • /res/drawable-mdpi for devices with medium-density screens

  • /res/drawable-ldpi for devices with low-density screens

We are going to create another drawable folder called simply /res/drawable. To do that, right-click on the res folder and choose NewFolder. For the name, enter drawable. You can now put your graphics that are independent of screen density in this folder. We’re going to assume you found some cool background graphics and that you saved the file in this new folder under the name background.png. Although Android supports many different file formats, PNG is preferred to the GIF standard because PNG is lossless and doesn’t require any patent licenses.

Tip

Although PNG officially stands for Portable Network Graphics, it is also commonly known as PNG’s Not Gif, to reflect its departure from the controversial GIF standard.

Remember that all resources are being “watched” by Eclipse, and the moment we put something in there, Eclipse ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required