The following is the first few sections of a chapter from The Busy Coder's Guide to Android Development, plus headings for the remaining major sections, to give you an idea about the content of the chapter.


Custom Drawables

Many times, our artwork can simply be some PNG or JPEG files, perhaps with different variations in different resource directories by density.

Sometimes, though, we need something more.

In addition to supporting standard PNG and JPEG files, Android has a number of custom drawable resource formats — mostly written in XML — that handle specific scenarios.

For example, you may wish to customize “the background” of a Button, but a Button really has several different background images for different circumstances (normal, pressed, focused, disabled, etc.). Android has a certain type of drawable resource that aggregates other drawable resources, indicating which of those other resources should be used in different circumstances (e.g., for a normal button use X, for a disabled button use Y).

In this chapter, we will explore these non-traditional types of “drawables” and how you can use them within your apps.

Prerequisites

Understanding this chapter requires that you have read the core chapters, particularly the ones on basic resources, basic widgets, and vector drawables.

Having read the chapters on animators and legacy animations would be useful.

Where Do These Things Go?

The preview of this section is en route to Mars.

ColorDrawable

The preview of this section is en route to Mars.

AnimationDrawable

The preview of this section is off trying to sweet-talk the Khaleesi into providing us with a dragon.

StateListDrawable

The preview of this section was accidentally identified as an Android 'tasty treat' by the Cookie Monster.

ColorStateList

The preview of this section is sleeping in.

LayerDrawable

The preview of this section is off trying to sweet-talk the Khaleesi into providing us with a dragon.

TransitionDrawable

The preview of this section was fed to a gremlin, after midnight.

LevelListDrawable

The preview of this section is unavailable right now, but if you leave your name and number at the sound of the tone, it might get back to you (BEEEEEEEEEEEEP!).

ScaleDrawable and ClipDrawable

The preview of this section is en route to Mars.

InsetDrawable

The preview of this section was lost in the sofa cushions.

ShapeDrawable

The preview of this section will not appear here for a while, due to a time machine mishap.

BitmapDrawable

The preview of this section was stepped on by Godzilla.

Composite Drawables

The preview of this section was the victim of a MITM ('Martian in the middle') attack.

A Stitch In Time Saves Nine

The preview of this section was accidentally identified as an Android 'tasty treat' by the Cookie Monster.