java.lang.Object | ||
↳ | android.graphics.drawable.Drawable | |
↳ | android.graphics.drawable.ShapeDrawable |
Known Direct Subclasses |
A Drawable object that draws primitive shapes. A ShapeDrawable takes a
Shape
object and manages its
presence on the screen. If no Shape is given, then the ShapeDrawable will
default to a RectShape
.
This object can be defined in an XML file with the <shape>
element.
For more information about how to use ShapeDrawable, read the Canvas and Drawables document. For more information about defining a ShapeDrawable in XML, read the Drawable Resources document.
Nested Classes | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
ShapeDrawable.ShaderFactory | Base class defines a factory object that is called each time the drawable is resized (has a new width or height). |
XML Attributes | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
android:bottom | Bottom padding. | ||||||||||
android:color | Defines the color of the shape. | ||||||||||
android:height | Defines the height of the shape. | ||||||||||
android:left | Left padding. | ||||||||||
android:right | Right padding. | ||||||||||
android:top | Top padding. | ||||||||||
android:width | Defines the width of the shape. |
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
ShapeDrawable constructor.
| |||||||||||
Creates a ShapeDrawable with a specified Shape.
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Applies the specified theme to this Drawable and its children.
| |||||||||||
Draw in its bounds (set via setBounds) respecting optional effects such
as alpha (set via setAlpha) and color filter (set via setColorFilter).
| |||||||||||
Gets the current alpha value for the drawable.
| |||||||||||
Return a mask of the configuration parameters for which this drawable
may change, requiring that it be re-created.
| |||||||||||
Return a
Drawable.ConstantState instance that holds the shared state of this Drawable.
| |||||||||||
Return the intrinsic height of the underlying drawable object.
| |||||||||||
Return the intrinsic width of the underlying drawable object.
| |||||||||||
Return the opacity/transparency of this Drawable.
| |||||||||||
Called to get the drawable to populate the Outline that defines its drawing area.
| |||||||||||
Return in padding the insets suggested by this Drawable for placing
content inside the drawable's bounds.
| |||||||||||
Returns the Paint used to draw the shape.
| |||||||||||
Returns the ShaderFactory used by this ShapeDrawable for requesting a
Shader .
| |||||||||||
Returns the Shape of this ShapeDrawable.
| |||||||||||
Inflate this Drawable from an XML resource optionally styled by a theme.
| |||||||||||
Indicates whether this drawable will change its appearance based on
state.
| |||||||||||
Make this drawable mutable.
| |||||||||||
Set the alpha level for this drawable [0..255].
| |||||||||||
Specify an optional color filter for the drawable.
| |||||||||||
Set to true to have the drawable dither its colors when drawn to a device
with fewer than 8-bits per color component.
| |||||||||||
Sets the intrinsic (default) height for this shape.
| |||||||||||
Sets the intrinsic (default) width for this shape.
| |||||||||||
Sets padding for this shape, defined by a Rect object.
| |||||||||||
Sets padding for the shape.
| |||||||||||
Sets a ShaderFactory to which requests for a
Shader object will be made.
| |||||||||||
Sets the Shape of this ShapeDrawable.
| |||||||||||
Specifies a tint for this drawable as a color state list.
| |||||||||||
Specifies a tint blending mode for this drawable.
|
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Subclasses override this to parse custom subelements.
| |||||||||||
Override this in your subclass to change appearance if you vary based on
the bounds.
| |||||||||||
Called from the drawable's draw() method after the canvas has been set to
draw the shape at (0,0).
| |||||||||||
Override this in your subclass to change appearance if you recognize the
specified state.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
android.graphics.drawable.Drawable
| |||||||||||
From class
java.lang.Object
|
Bottom padding.
Must be a dimension value, which is a floating point number appended with a unit such as "14.5sp
".
Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size),
in (inches), mm (millimeters).
This may also be a reference to a resource (in the form
"@[package:]type:name
") or
theme attribute (in the form
"?[package:][type:]name
")
containing a value of this type.
This corresponds to the global attribute
resource symbol bottom
.
Defines the color of the shape.
Must be a color value, in the form of "#rgb
", "#argb
",
"#rrggbb
", or "#aarrggbb
".
This may also be a reference to a resource (in the form
"@[package:]type:name
") or
theme attribute (in the form
"?[package:][type:]name
")
containing a value of this type.
This corresponds to the global attribute
resource symbol color
.
Defines the height of the shape.
Must be a dimension value, which is a floating point number appended with a unit such as "14.5sp
".
Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size),
in (inches), mm (millimeters).
This may also be a reference to a resource (in the form
"@[package:]type:name
") or
theme attribute (in the form
"?[package:][type:]name
")
containing a value of this type.
This corresponds to the global attribute
resource symbol height
.
Left padding.
Must be a dimension value, which is a floating point number appended with a unit such as "14.5sp
".
Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size),
in (inches), mm (millimeters).
This may also be a reference to a resource (in the form
"@[package:]type:name
") or
theme attribute (in the form
"?[package:][type:]name
")
containing a value of this type.
This corresponds to the global attribute
resource symbol left
.
Right padding.
Must be a dimension value, which is a floating point number appended with a unit such as "14.5sp
".
Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size),
in (inches), mm (millimeters).
This may also be a reference to a resource (in the form
"@[package:]type:name
") or
theme attribute (in the form
"?[package:][type:]name
")
containing a value of this type.
This corresponds to the global attribute
resource symbol right
.
Top padding.
Must be a dimension value, which is a floating point number appended with a unit such as "14.5sp
".
Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size),
in (inches), mm (millimeters).
This may also be a reference to a resource (in the form
"@[package:]type:name
") or
theme attribute (in the form
"?[package:][type:]name
")
containing a value of this type.
This corresponds to the global attribute
resource symbol top
.
Defines the width of the shape.
Must be a dimension value, which is a floating point number appended with a unit such as "14.5sp
".
Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size),
in (inches), mm (millimeters).
This may also be a reference to a resource (in the form
"@[package:]type:name
") or
theme attribute (in the form
"?[package:][type:]name
")
containing a value of this type.
This corresponds to the global attribute
resource symbol width
.
Creates a ShapeDrawable with a specified Shape.
s | the Shape that this ShapeDrawable should be |
---|
Applies the specified theme to this Drawable and its children.
Draw in its bounds (set via setBounds) respecting optional effects such as alpha (set via setAlpha) and color filter (set via setColorFilter).
canvas | The canvas to draw into |
---|
Gets the current alpha value for the drawable. 0 means fully transparent, 255 means fully opaque. This method is implemented by Drawable subclasses and the value returned is specific to how that class treats alpha. The default return value is 255 if the class does not override this method to return a value specific to its use of alpha.
Return a mask of the configuration parameters for which this drawable
may change, requiring that it be re-created. The default implementation
returns whatever was provided through
setChangingConfigurations(int)
or 0 by default. Subclasses
may extend this to or in the changing configurations of any other
drawables they hold.
ActivityInfo
.Return a Drawable.ConstantState
instance that holds the shared state of this Drawable.
Return the intrinsic height of the underlying drawable object. Returns -1 if it has no intrinsic height, such as with a solid color.
Return the intrinsic width of the underlying drawable object. Returns -1 if it has no intrinsic width, such as with a solid color.
Return the opacity/transparency of this Drawable. The returned value is
one of the abstract format constants in
PixelFormat
:
UNKNOWN
,
TRANSLUCENT
,
TRANSPARENT
, or
OPAQUE
.
Generally a Drawable should be as conservative as possible with the
value it returns. For example, if it contains multiple child drawables
and only shows one of them at a time, if only one of the children is
TRANSLUCENT and the others are OPAQUE then TRANSLUCENT should be
returned. You can use the method resolveOpacity(int, int)
to perform a
standard reduction of two opacities to the appropriate single output.
Note that the returned value does not take into account a
custom alpha or color filter that has been applied by the client through
the setAlpha(int)
or setColorFilter(ColorFilter)
methods.
Called to get the drawable to populate the Outline that defines its drawing area.
This method is called by the default ViewOutlineProvider
to define
the outline of the View.
The default behavior defines the outline to be the bounding rectangle of 0 alpha. Subclasses that wish to convey a different shape or alpha value must override this method.
Return in padding the insets suggested by this Drawable for placing content inside the drawable's bounds. Positive values move toward the center of the Drawable (set Rect.inset).
Returns the ShaderFactory used by this ShapeDrawable for requesting a
Shader
.
Inflate this Drawable from an XML resource optionally styled by a theme.
r | Resources used to resolve attribute values |
---|---|
parser | XML parser from which to inflate this Drawable |
attrs | Base set of attribute values |
theme | Theme to apply, may be null |
Indicates whether this drawable will change its appearance based on state. Clients can use this to determine whether it is necessary to calculate their state and call setState.
Make this drawable mutable. This operation cannot be reversed. A mutable drawable is guaranteed to not share its state with any other drawable. This is especially useful when you need to modify properties of drawables loaded from resources. By default, all drawables instances loaded from the same resource share a common state; if you modify the state of one instance, all the other instances will receive the same modification. Calling this method on a mutable Drawable will have no effect.
Set the alpha level for this drawable [0..255]. Note that this drawable also has a color in its paint, which has an alpha as well. These two values are automatically combined during drawing. Thus if the color's alpha is 75% (i.e. 192) and the drawable's alpha is 50% (i.e. 128), then the combined alpha that will be used during drawing will be 37.5% (i.e. 96).
Specify an optional color filter for the drawable. Pass null
to
remove any existing color filter.
cf | the color filter to apply, or null to remove the
existing color filter
|
---|
Set to true to have the drawable dither its colors when drawn to a device with fewer than 8-bits per color component. This can improve the look on those devices, but can also slow down the drawing a little.
Sets the intrinsic (default) height for this shape.
height | the intrinsic height (in pixels) |
---|
Sets the intrinsic (default) width for this shape.
width | the intrinsic width (in pixels) |
---|
Sets padding for this shape, defined by a Rect object. Define the padding in the Rect object as: left, top, right, bottom.
Sets padding for the shape.
left | padding for the left side (in pixels) |
---|---|
top | padding for the top (in pixels) |
right | padding for the right side (in pixels) |
bottom | padding for the bottom (in pixels) |
Sets a ShaderFactory to which requests for a
Shader
object will be made.
fact | an instance of your ShaderFactory implementation |
---|
Specifies a tint for this drawable as a color state list.
Setting a color filter via setColorFilter(ColorFilter)
overrides
tint.
tint | Color state list to use for tinting this drawable, or null to clear the tint |
---|
Specifies a tint blending mode for this drawable.
Setting a color filter via setColorFilter(ColorFilter)
overrides
tint.
tintMode | A Porter-Duff blending mode |
---|
Subclasses override this to parse custom subelements. If you handle it, return true, else return super.inflateTag(...).
Override this in your subclass to change appearance if you vary based on the bounds.
Called from the drawable's draw() method after the canvas has been set to draw the shape at (0,0). Subclasses can override for special effects such as multiple layers, stroking, etc.
Override this in your subclass to change appearance if you recognize the specified state.