Android Programming The Big Nerd Ranch Guide by Bill Phillips, Chris Stewart, Kristin Marsicano (z-lib.org)

(gtxtreme123) #1

Chapter 23  XML Drawables


Run BeatBox and press on a button or two. You will see a nice ring around the pressed interface
(Figure 23.5). Even slicker.


Figure 23.5  BeatBox complete


With the layer list drawable addition, BeatBox is now complete. Remember how plain BeatBox used to
look? You now have something special and uniquely identifiable. Making your app a pleasure to look
at makes it fun to use, and that will pay off in popularity.


For the More Curious: Why Bother with XML Drawables?


You will always want a pressed state for your buttons, so state list drawables are a critical component
of any Android app. But what about shape drawables and layer list drawables? Should you use them?


XML drawables are flexible. You can use them for many purposes and you can easily update them in
the future. With a combination of layer list drawables and shape drawables, you can create complex
backgrounds without using an image editor. If you decide to change the color scheme in BeatBox,
updating the colors in an XML drawable is easy.


In this chapter, you defined your XML drawables in the drawable directory with no resource qualifiers
for the screen density. This is because XML drawables are density independent. With a standard
background that is an image, you will typically create multiple versions of that same image in different
densities so that the image will look crisp on most devices. XML drawables only need to be defined
once and will look crisp at any screen density.

Free download pdf