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 was lost in the sofa cushions.

ColorDrawable

The preview of this section was eaten by a grue.

AnimationDrawable

The preview of this section apparently resembled a Pokémon.

StateListDrawable

The preview of this section was eaten by a grue.

ColorStateList

The preview of this section took that left turn at Albuquerque.

LayerDrawable

The preview of this section was stepped on by Godzilla.

TransitionDrawable

The preview of this section left for Hollywood to appear in a reality TV show.

LevelListDrawable

The preview of this section is out seeking fame and fortune as the Dread Pirate Roberts.

ScaleDrawable and ClipDrawable

The preview of this section is out seeking fame and fortune as the Dread Pirate Roberts.

InsetDrawable

The preview of this section did not survive Thanos's finger snap.

ShapeDrawable

The preview of this section was traded for a bag of magic beans.

BitmapDrawable

The preview of this section was abducted by space aliens.

Composite Drawables

The preview of this section apparently resembled a Pokémon.

A Stitch In Time Saves Nine

The preview of this section is presently indisposed.