Android Drawable XML Documentation

The missing manual! Each of the top-level elements are useable in Android XML files, in /res/drawable/. Some of them are allowed to be contained in others and this is noted below.

ElementClassDescription
<animated-rotate>AnimatedRotateDrawableA Drawable that can animate a rotation of another Drawable.
<animation-list>AnimationDrawableAn object used to create frame-by-frame animations, defined by a series of Drawable objects, which can be used as a View object's background.
<bitmap>BitmapDrawableA Drawable that wraps a bitmap and can be tiled, stretched, or aligned.
<clip>ClipDrawableA Drawable that clips another Drawable based on this Drawable's current level value. You can control how much the child Drawable gets clipped in width and height based on the level, as well as a gravity to control where it is placed in its overall container. Most often used to implement things like progress bars.
<color>ColorDrawableA specialized Drawable that fills the Canvas with a specified color, with respect to the clip region.
<inset>InsetDrawableA Drawable that insets another Drawable by a specified distance. This is used when a View needs a background that is smaller than the View's actual bounds.
<layer-list>LayerDrawableA Drawable that manages an array of other Drawables. These are drawn in array order.
<level-list>LevelListDrawableA resource that manages a number of alternate Drawables, each assigned a maximum numerical value.
<nine-patch>NinePatchDrawableA resizeable bitmap, with stretchable areas that you define.
<rotate>RotateDrawableA Drawable that can rotate another Drawable based on the current level value. The start and end angles of rotation can be controlled to map any circular arc to the level values range.
<scale>ScaleDrawableA Drawable that changes the size of another Drawable based on its current level value.
<selector>StateListDrawableLets you assign a number of graphic images to a single Drawable and swap out the visible item based on state.
<shape>GradientDrawableBasic method for drawing shapes via XML.
<transition>TransitionDrawableAn extension of <layer-list> that is intended to cross-fade between the first and second layer. The format is exactly the same as <layer-list>.

<animated-rotate>

A Drawable that can animate a rotation of another Drawable.

Attributes

NameTypeDefaultDescription
visiblebooleanparent|trueDetermines if drawable is visible.
frameDurationinteger150The duration of each frame, in milliseconds.
framesCountinteger12Number of frames of rotation to animate.
pivotXfloat|fraction.5The pivot point, as a fraction of the width.
pivotYfloat|fraction.5The pivot point, as a fraction of the height.
drawablereferencenullThe drawable to use for this item. Either this must be present or a drawable subelement must exist.

Children

ElementDescription
<[any drawable tag]>Any drawable xml. Either this must be present or the 'drawable' attribute must be set.

<[any drawable tag]>

Any drawable xml. Either this must be present or the 'drawable' attribute must be set.

<animation-list>

An object used to create frame-by-frame animations, defined by a series of Drawable objects, which can be used as a View object's background.

Attributes

NameTypeDefaultDescription
visiblebooleanparent|trueDetermines if drawable is visible.
variablePaddingbooleanfalseIf true, allows the drawable's padding to change based on the current state that is selected.
oneshotbooleanfalseIf true, the animation will only run a single time and then stop.

Children

ElementDescription
<item>A drawable for a frame of animation.

<item>

A drawable for a frame of animation.

Attributes

NameTypeDefaultDescription
drawablereferencenullThe drawable to use for this item. Either this must be present or a drawable subelement must exist.
durationinteger-1The duration of this frame, in milliseconds. Required.

Children

ElementDescription
<[any drawable tag]>Any drawable xml. Either this must be present or the 'drawable' attribute must be set.

<[any drawable tag]>

Any drawable xml. Either this must be present or the 'drawable' attribute must be set.

<bitmap>

A Drawable that wraps a bitmap and can be tiled, stretched, or aligned.

Attributes

NameTypeDefaultDescription
srcreferenceN/AThe source for the Bitmap. Required.
antialiasbooleanfalseEnables or disables antialiasing.
filterbooleantrueEnables or disables bitmap filtering. Filtering is used when the bitmap is shrunk or stretched to smooth its apperance.
ditherbooleantrueEnables or disables dithering of the bitmap if the bitmap does not have the same pixel configuration as the screen (for instance: a ARGB 8888 bitmap with an RGB 565 screen).
gravityenum (top, bottom, left, right, center_vertical, fill_vertical, center_horizontal, fill_horizontal, center, fill, clip_vertical, clip_horizontal)fillDefines the gravity for the bitmap. The gravity indicates where to position the drawable in its container if the bitmap is smaller than the container.
tileModeenum (disabled, clamp, repeat, mirror)disabledDefines the tile mode. When the tile mode is enabled, the bitmap is repeated. Gravity is ignored when the tile mode is enabled. Values can be 'clamp' (replicates the edge color), 'repeat' (repeats the bitmap in both directions), 'mirror' (repeats the shader's image horizontally and vertically, alternating mirror images so that adjacent images always seam).

<clip>

A Drawable that clips another Drawable based on this Drawable's current level value. You can control how much the child Drawable gets clipped in width and height based on the level, as well as a gravity to control where it is placed in its overall container. Most often used to implement things like progress bars.

Attributes

NameTypeDefaultDescription
clipOrientationenum (horizontal, vertical)horizontalThe orientation for the clip.
gravityenum (top, bottom, left, right, center_vertical, fill_vertical, center_horizontal, fill_horizontal, center, fill, clip_vertical, clip_horizontal)leftSpecifies where to clip within the drawable.
drawablereferencenullThe drawable to use for this item. Either this must be present or a drawable subelement must exist.

Children

ElementDescription
<[any drawable tag]>Any drawable xml. Either this must be present or the 'drawable' attribute must be set.

<[any drawable tag]>

Any drawable xml. Either this must be present or the 'drawable' attribute must be set.

<color>

A specialized Drawable that fills the Canvas with a specified color, with respect to the clip region.

Attributes

NameTypeDefaultDescription
colorcolorThe color to fill the Canvas with.

<inset>

A Drawable that insets another Drawable by a specified distance. This is used when a View needs a background that is smaller than the View's actual bounds.

Attributes

NameTypeDefaultDescription
drawablereferencenullThe drawable to use for this item. Either this must be present or a drawable subelement must exist.
visiblebooleanparent|trueDetermines if drawable is visible.
insetLeftdimension0The left padding for the inset.
insetRightdimension0The right padding for the inset.
insetTopdimension0The top padding for the inset.
insetBottomdimension0The bottom padding for the inset.

Children

ElementDescription
<[any drawable tag]>Any drawable xml. Either this must be present or the 'drawable' attribute must be set.

<[any drawable tag]>

Any drawable xml. Either this must be present or the 'drawable' attribute must be set.

<layer-list>

A Drawable that manages an array of other Drawables. These are drawn in array order.

Children

ElementDescription
<item>Layer for the layer-list.

<item>

Layer for the layer-list.

Attributes

NameTypeDefaultDescription
drawablereferencenullThe drawable to use for this item. Either this must be present or a drawable subelement must exist.
leftdimension0Left padding of this layer.
topdimension0Top padding of this layer.
rightdimension0Right padding of this layer.
bottomdimension0Bottom padding of this layer.
ididView.NO_IDThe id of this layer.

Children

ElementDescription
<[any drawable tag]>Any drawable xml. Either this must be present or the 'drawable' attribute must be set.

<[any drawable tag]>

Any drawable xml. Either this must be present or the 'drawable' attribute must be set.

<level-list>

A resource that manages a number of alternate Drawables, each assigned a maximum numerical value.

Children

ElementDescription
<item>Drawable for the level.

<item>

Drawable for the level.

Attributes

NameTypeDefaultDescription
drawablereferencenullThe drawable to use for this item. Either this must be present or a drawable subelement must exist.
minLevelinteger0The minimum level allowed for this item.
maxLevelinteger0The maximum level allowed for this item. Required for each item tag.

Children

ElementDescription
<[any drawable tag]>Any drawable xml. Either this must be present or the 'drawable' attribute must be set.

<[any drawable tag]>

Any drawable xml. Either this must be present or the 'drawable' attribute must be set.

<nine-patch>

A resizeable bitmap, with stretchable areas that you define.

Attributes

NameTypeDefaultDescription
srcreferenceN/AThe source for the nine patch. Required.
ditherbooleantrueEnables or disables dithering of the bitmap if the bitmap does not have the same pixel configuration as the screen (for instance: a ARGB 8888 bitmap with an RGB 565 screen).

<rotate>

A Drawable that can rotate another Drawable based on the current level value. The start and end angles of rotation can be controlled to map any circular arc to the level values range.

Attributes

NameTypeDefaultDescription
visiblebooleanparent|trueDetermines if drawable is visible.
fromDegreesfloat0.0The initial rotation, used on the lowest level.
toDegreesfloat360.0The final rotation, used on the highest level.
pivotXfloat|fraction.5The pivot point, as a fraction of the width.
pivotYfloat|fraction.5The pivot point, as a fraction of the height.
drawablereferencenullThe drawable to use for this item. Either this must be present or a drawable subelement must exist.

Children

ElementDescription
<[any drawable tag]>Any drawable xml. Either this must be present or the 'drawable' attribute must be set.

<[any drawable tag]>

Any drawable xml. Either this must be present or the 'drawable' attribute must be set.

<scale>

A Drawable that changes the size of another Drawable based on its current level value.

Attributes

NameTypeDefaultDescription
scaleWidthstring|percentage-1Scale width, expressed as a percentage of the drawable's bound. The value's format is XX%. For instance: 100%, 12.5%, etc.
scaleHeightstring|percentage-1Scale height, expressed as a percentage of the drawable's bound. The value's format is XX%. For instance: 100%, 12.5%, etc.
scaleGravityenum (top, bottom, left, right, center_vertical, fill_vertical, center_horizontal, fill_horizontal, center, fill, clip_vertical, clip_horizontal)left Specifies where the drawable is positioned after scaling.
drawablereferenceN/AThe drawable to scale; must be defined.

<selector>

Lets you assign a number of graphic images to a single Drawable and swap out the visible item based on state.

Attributes

NameTypeDefaultDescription
visiblebooleanparent|trueDetermines if drawable is visible.
variablePaddingbooleanfalseIf true, allows the drawable's padding to change based on the current state that is selected.
constantSizebooleanfalseIf true, the drawable's reported internal size will remain constant as the state changes; the size is the maximum of all of the states.
ditherbooleantrueSet to true to have the drawable dither its colors when drawn to a device with fewer than 8-bits per color component.

Children

ElementDescription
<item>Sets up a drawable for a particular collection of states.

<item>

Sets up a drawable for a particular collection of states.

Attributes

NameTypeDefaultDescription
drawablereferencenullThe drawable to use for this item. Either this must be present or a drawable subelement must exist.
state_focusedbooleanfalseThis state indicates the view is focused.
state_window_focusedbooleanfalseThis state indicates the view's window has focus.
state_enabledbooleanfalseThis state indicates the view is enabled.
state_checkablebooleanfalseThis state indicates the view can be checked
state_checkedbooleanfalseThis state indicates the view is checked.
state_selectedbooleanfalseThis state indicates the view is selected.
state_activebooleanfalseUsed by SlidingTab. This state indicates that the view is active.
state_singlebooleanfalseUsed by views that contain lists of items. This state indicates that the view is showing only one item.
state_firstbooleanfalseUsed by views that contain lists of items. This state indicates that the view is showing the first item.
state_middlebooleanfalseUsed by views that contain lists of items. This state indicates that the view is showing the middle item.
state_lastbooleanfalseUsed by views that contain lists of items. This state indicates that the view is showing the last item.
state_pressedbooleanfalseUsed by views that contain lists of items. This state indicates that the view is pressed.

Children

ElementDescription
<[any drawable tag]>Any drawable xml. Either this must be present or the 'drawable' attribute must be set.

<[any drawable tag]>

Any drawable xml. Either this must be present or the 'drawable' attribute must be set.

<shape>

Basic method for drawing shapes via XML.

Attributes

NameTypeDefaultDescription
visiblebooleanparent|trueDetermines if drawable is visible.
shapeenum (rectangle, oval, line, ring)rectangleDetermines the shape: rectangle (shape is a rectangle, possibly with rounded corners); oval (shape is an ellipse); line (shape is a line); ring (shape is a ring).
innerRadiusRatiofloat3.0Only valid if shape == 'ring'. Inner radius of the ring expressed as a ratio of the ring's width. For instance, if innerRadiusRatio=3, then the inner radius equals the ring's width divided by 3. This value is ignored if innerRadius is defined.
innerRadiusfloat-1Only valid if shape == 'ring'. Inner radius of the ring. When defined, innerRadiusRatio is ignored. When undefined, innerRadiusRatio's default is used.
thicknessRatiofloat9.0Only valid if shape == 'ring'. Thickness of the ring expressed as a ratio of the ring's width. For instance, if thicknessRatio=9, then the thickness equals the ring's width divided by 9. This value is ignored if thickness is defined. Default value is 9.
thicknessfloat-1Only valid if shape == 'ring'. Thickness of the ring. When defined, thicknessRatio is ignored. When undefined, thicknessRatio's default is used.
useLevelbooleantrueOnly valid if shape == 'ring'. Allows one to draw only part of the ring (arc-wise), by modifying the drawable's level. This setting only makes sense in context of a <level-list> (LevelListDrawable).

Children

ElementDescription
<size>Determines the size of the shape.
<gradient>Adds a background gradient to the shape.
<solid>Adds a solid background color to the shape. Overides gradient element.
<stroke>Adds a border to the shape.
<corners>Adds rounded corners to the shape.
<padding>The padding for the content within this drawable. (Does not pad graphics in any way.)

<size>

Determines the size of the shape.

Attributes

NameTypeDefaultDescription
widthdimension-1Width of the shape.
heightdimension-1Height of the shape.

<gradient>

Adds a background gradient to the shape.

Attributes

NameTypeDefaultDescription
startColorcolor0The color at the start of the gradient.
centerColorcolor0The color in the center of the gradient. Optional; if not included, there is no center color.
endColorcolor0The color at the end of the gradient.
typeenum (linear, radial, sweep)linearDetermines the type of gradient.
centerXfloat|fraction.5Determines the location of the centerColor. Ranges from 0 to 1. Ignored if centerColor is undefined.
centerYfloat|fraction.5Determines the location of the centerColor. Ranges from 0 to 1. Ignored if centerColor is undefined.
anglefloat0Only valid if type == 'linear'. Determines the angle of a linear gradient. Must be a multiple of 45 degrees.
gradientRadiusfloat|fractionN/AOnly valid if type == 'radial' or 'sweep'. Required if type == 'radial'. Determines the radius of the gradient.
useLevelbooleanfalseDetermines the amount of the gradient to be drawn, based on the level of the shape. Affects all three gradient types.

<solid>

Adds a solid background color to the shape. Overides gradient element.

Attributes

NameTypeDefaultDescription
colorcolor0The color of the background.

<stroke>

Adds a border to the shape.

Attributes

NameTypeDefaultDescription
widthdimension0The width of the stroke.
colorcolor0The color of the stroke.
dashWidthdimension0The width of each dash. Ignored unless dashGap is also defined.
dashGapdimension0The width of gaps between eahc dash. Ignored unless dashWidth is also defined.

<corners>

Adds rounded corners to the shape.

Attributes

NameTypeDefaultDescription
radiusdimension0The radius of every corner.
topLeftRadiusdimensionradiusDetermines the radius of the top left corner. Ignored unless radius for all corners is defined, either through 'radius' or the other corners' attributes.
topRightRadiusdimensionradiusDetermines the radius of the top right corner. Ignored unless radius for all corners is defined, either through 'radius' or the other corners' attributes.
bottomLeftRadiusdimensionradiusDetermines the radius of the bottom left corner (buggy; is actually bottom right corner). Ignored unless radius for all corners is defined, either through 'radius' or the other corners' attributes.
bottomRightRadiusdimensionradiusDetermines the radius of the bottom right corner (buggy; is actually bottom left corner). Ignored unless radius for all corners is defined, either through 'radius' or the other corners' attributes.

<padding>

The padding for the content within this drawable. (Does not pad graphics in any way.)

Attributes

NameTypeDefaultDescription
leftdimension0Left padding.
topdimension0Top padding.
rightdimension0Right padding.
bottomdimension0Bottom padding.

<transition>

An extension of <layer-list> that is intended to cross-fade between the first and second layer. The format is exactly the same as <layer-list>.