GradientDrawable
open class GradientDrawable : Drawable
kotlin.Any | ||
↳ | android.graphics.drawable.Drawable | |
↳ | android.graphics.drawable.GradientDrawable |
A Drawable with a color gradient for buttons, backgrounds, etc.
It can be defined in an XML file with the <shape>
element. For more information, see the guide to Drawable Resources.
Summary
Nested classes | |
---|---|
Controls how the gradient is oriented relative to the drawable's bounds |
XML attributes | |
---|---|
android:angle |
Angle of the gradient, used only with linear gradient. |
android:bottom |
Amount of bottom padding inside the gradient shape. |
android:centerColor |
Optional center color. |
android:centerX |
X-position of the center point of the gradient within the shape as a fraction of the width. |
android:centerY |
Y-position of the center point of the gradient within the shape as a fraction of the height. |
android:color |
Solid color for the gradient shape. |
android:color |
Color of the gradient shape's stroke. |
android:dashGap |
Gap between dashes in the stroke. |
android:dashWidth |
Length of a dash in the stroke. |
android:endColor |
End color of the gradient. |
android:gradientRadius |
Radius of the gradient, used only with radial gradient. |
android:height |
Height of the gradient shape. |
android:innerRadius |
Inner radius of the ring. |
android:innerRadiusRatio |
Inner radius of the ring expressed as a ratio of the ring's width. |
android:left |
Amount of left padding inside the gradient shape. |
android:right |
Amount of right padding inside the gradient shape. |
android:shape |
Indicates what shape to fill with a gradient. |
android:startColor |
Start color of the gradient. |
android:thickness |
Thickness of the ring. |
android:thicknessRatio |
Thickness of the ring expressed as a ratio of the ring's width. |
android:top |
Amount of top padding inside the gradient shape. |
android:type |
Type of gradient. |
android:useLevel |
Whether the drawable level value (see android.graphics.drawable.Drawable#getLevel() ) is used to scale the shape. |
android:useLevel |
Whether the drawable level value (see android.graphics.drawable.Drawable#getLevel() ) is used to scale the gradient. |
android:visible |
Indicates whether the drawable should intially be visible. |
android:width |
Width of the gradient shape. |
android:width |
Width of the gradient shape's stroke. |
Constants | |
---|---|
static Int |
Shape is a line |
static Int |
Gradient is linear (default.) |
static Int |
Shape is an ellipse |
static Int |
Gradient is circular. |
static Int |
Shape is a rectangle, possibly with rounded corners |
static Int |
Shape is a ring. |
static Int |
Gradient is a sweep. |
Public constructors | |
---|---|
GradientDrawable(orientation: GradientDrawable.Orientation!, colors: IntArray!) Create a new gradient drawable given an orientation and an array of colors for the gradient. |
Public methods | |
---|---|
open Unit |
Applies the specified theme to this Drawable and its children. |
open Boolean | |
open Unit | |
open Int |
getAlpha() |
open Int |
Return a mask of the configuration parameters for which this drawable may change, requiring that it be re-created. |
open ColorStateList? |
getColor() Returns the color state list used to fill the shape, or |
open ColorFilter? |
Returns the current color filter, or |
open IntArray? |
Returns the colors used to draw the gradient, or |
open Drawable.ConstantState? | |
open FloatArray? |
Returns the radii for each of the 4 corners. |
open Float |
Returns the radius for the corners of the gradient, that was previously set with |
open Float |
Returns the X-position of the center of the gradient as a fraction of the width. |
open Float |
Returns the Y-position of the center of this gradient as a fraction of the height. |
open Float |
Returns the radius of the gradient in pixels. |
open Int |
Returns the type of gradient used by this drawable, one of |
open Int |
Return the inner radius of the ring |
open Float |
Return the inner radius of the ring expressed as a ratio of the ring's width. |
open Int | |
open Int | |
open Int | |
open Insets | |
open GradientDrawable.Orientation! |
Returns the orientation of the gradient defined in this drawable. |
open Unit |
getOutline(outline: Outline) |
open Boolean |
getPadding(padding: Rect) |
open Int |
getShape() Returns the type of shape used by this drawable, one of |
open Int |
Return the thickness of the ring |
open Float |
Return the thickness ratio of the ring expressed as a ratio of the ring's width. |
open Boolean |
Returns whether this drawable's |
open Boolean | |
open Unit |
inflate(r: Resources, parser: XmlPullParser, attrs: AttributeSet, theme: Resources.Theme?) Inflate this Drawable from an XML resource optionally styled by a theme. |
open Boolean | |
open Drawable |
mutate() |
open Unit | |
open Unit |
setColor(colorStateList: ColorStateList?) Changes this drawable to use a single color state list instead of a gradient. |
open Unit |
Changes this drawable to use a single color instead of a gradient. |
open Unit |
setColorFilter(colorFilter: ColorFilter?) Specify an optional color filter for the drawable. |
open Unit |
Sets the colors used to draw the gradient. |
open Unit |
setColors(colors: IntArray?, offsets: FloatArray?) Sets the colors and offsets used to draw the gradient. |
open Unit |
setCornerRadii(radii: FloatArray?) Specifies radii for each of the 4 corners. |
open Unit |
setCornerRadius(radius: Float) Specifies the radius for the corners of the gradient. |
open Unit | |
open Unit |
setGradientCenter(x: Float, y: Float) Sets the position of the center of the gradient as a fraction of the width and height. |
open Unit |
setGradientRadius(gradientRadius: Float) Sets the radius of the gradient. |
open Unit |
setGradientType(gradient: Int) Sets the type of gradient used by this drawable. |
open Unit |
setInnerRadius(innerRadius: Int) Configure the inner radius of the ring. |
open Unit |
setInnerRadiusRatio(innerRadiusRatio: Float) Inner radius of the ring expressed as a ratio of the ring's width. |
open Unit |
setOrientation(orientation: GradientDrawable.Orientation!) Sets the orientation of the gradient defined in this drawable. |
open Unit |
setPadding(left: Int, top: Int, right: Int, bottom: Int) Configure the padding of the gradient shape |
open Unit |
Sets the type of shape used to draw the gradient. |
open Unit |
Sets the size of the shape drawn by this drawable. |
open Unit |
setStroke(width: Int, colorStateList: ColorStateList!) Set the stroke width and color state list for the drawable. |
open Unit |
setStroke(width: Int, colorStateList: ColorStateList!, dashWidth: Float, dashGap: Float) Set the stroke width and color state list for the drawable. |
open Unit |
Set the stroke width and color for the drawable. |
open Unit |
Set the stroke width and color for the drawable. |
open Unit |
setThickness(thickness: Int) Configure the thickness of the ring. |
open Unit |
setThicknessRatio(thicknessRatio: Float) Configure the thickness of the ring expressed as a ratio of the ring's width. |
open Unit |
setTintBlendMode(blendMode: BlendMode!) Specifies a tint blending mode for this drawable. |
open Unit |
setTintList(tint: ColorStateList?) Specifies tint color for this drawable as a color state list. |
open Unit |
setUseLevel(useLevel: Boolean) Sets whether this drawable's |
Protected methods | |
---|---|
open Unit |
onBoundsChange(r: Rect) |
open Boolean |
onLevelChange(level: Int) |
open Boolean |
onStateChange(stateSet: IntArray) |
Inherited functions | |
---|---|
XML attributes
android:angle
android:angle
May be a floating point value, such as "1.2
".
android:bottom
android:bottom
May 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), and mm (millimeters).
android:centerColor
android:centerColor
May be a color value, in the form of "rgb
", "argb
", "rrggbb
", or "aarrggbb
".
android:centerX
android:centerX
May be a floating point value, such as "1.2
".
May be a fractional value, which is a floating point number appended with either % or %p, such as "14.5%
". The % suffix always means a percentage of the base size; the optional %p suffix provides a size relative to some parent container.
android:centerY
android:centerY
May be a floating point value, such as "1.2
".
May be a fractional value, which is a floating point number appended with either % or %p, such as "14.5%
". The % suffix always means a percentage of the base size; the optional %p suffix provides a size relative to some parent container.
android:color
android:color
May be a color value, in the form of "rgb
", "argb
", "rrggbb
", or "aarrggbb
".
android:color
android:color
May be a color value, in the form of "rgb
", "argb
", "rrggbb
", or "aarrggbb
".
android:dashGap
android:dashGap
May 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), and mm (millimeters).
android:dashWidth
android:dashWidth
May 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), and mm (millimeters).
android:endColor
android:endColor
May be a color value, in the form of "rgb
", "argb
", "rrggbb
", or "aarrggbb
".
android:gradientRadius
android:gradientRadius
May be a floating point value, such as "1.2
".
May 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), and mm (millimeters).
May be a fractional value, which is a floating point number appended with either % or %p, such as "14.5%
". The % suffix always means a percentage of the base size; the optional %p suffix provides a size relative to some parent container.
android:height
android:height
May 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), and mm (millimeters).
android:innerRadius
android:innerRadius
May 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), and mm (millimeters).
android:innerRadiusRatio
android:innerRadiusRatio
May be a floating point value, such as "1.2
".
android:left
android:left
May 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), and mm (millimeters).
android:right
android:right
May 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), and mm (millimeters).
android:shape
android:shape
Must be one of the following constant values.
Constant | Value | Description |
---|---|---|
line | 2 | Line shape. |
oval | 1 | Oval shape. |
rectangle | 0 | Rectangle shape, with optional rounder corners. |
ring | 3 | Ring shape. |
android:startColor
android:startColor
May be a color value, in the form of "rgb
", "argb
", "rrggbb
", or "aarrggbb
".
android:thickness
android:thickness
May 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), and mm (millimeters).
android:thicknessRatio
android:thicknessRatio
May be a floating point value, such as "1.2
".
android:top
android:top
May 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), and mm (millimeters).
android:type
android:type
Must be one of the following constant values.
Constant | Value | Description |
---|---|---|
linear | 0 | Linear gradient extending across the center point. |
radial | 1 | Radial gradient extending from the center point outward. |
sweep | 2 | Sweep (or angular) gradient sweeping counter-clockwise around the center point. |
android:useLevel
android:useLevel
android.graphics.drawable.Drawable#getLevel()
) is used to scale the shape. Scaling behavior depends on the shape type. For "ring", the angle is scaled from 0 to 360. For all other types, there is no effect. The default value is true.
May be a boolean value, such as "true
" or "false
".
android:useLevel
android:useLevel
android.graphics.drawable.Drawable#getLevel()
) is used to scale the gradient. Scaling behavior varies based on gradient type. For "linear", adjusts the ending position along the gradient's axis of orientation. For "radial", adjusts the outer radius. For "sweep", adjusts the ending angle. The default value is false.
May be a boolean value, such as "true
" or "false
".
android:visible
android:visible
May be a boolean value, such as "true
" or "false
".
android:width
android:width
May 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), and mm (millimeters).
android:width
android:width
May 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), and mm (millimeters).
Constants
LINEAR_GRADIENT
static val LINEAR_GRADIENT: Int
Gradient is linear (default.)
Value: 0
RECTANGLE
static val RECTANGLE: Int
Shape is a rectangle, possibly with rounded corners
Value: 0
Public constructors
GradientDrawable
GradientDrawable(
orientation: GradientDrawable.Orientation!,
colors: IntArray!)
Create a new gradient drawable given an orientation and an array of colors for the gradient.
Public methods
applyTheme
open fun applyTheme(t: Resources.Theme): Unit
Applies the specified theme to this Drawable and its children.
Parameters | |
---|---|
t |
Resources.Theme: This value cannot be null . |
draw
open fun draw(canvas: Canvas): Unit
Parameters | |
---|---|
canvas |
Canvas: The canvas to draw into This value cannot be null . |
getAlpha
open fun getAlpha(): Int
Return | |
---|---|
Int |
Value is between 0 and 255 inclusive |
getChangingConfigurations
open fun getChangingConfigurations(): Int
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.
getColor
open fun getColor(): ColorStateList?
Returns the color state list used to fill the shape, or null
if the shape is filled with a gradient or has no fill color.
Return | |
---|---|
ColorStateList? |
the color state list used to fill this gradient, or null |
See Also
getColorFilter
open fun getColorFilter(): ColorFilter?
Returns the current color filter, or null
if none set.
Return | |
---|---|
ColorFilter? |
This value may be null . |
getColors
open fun getColors(): IntArray?
Returns the colors used to draw the gradient, or null
if the gradient is drawn using a single color or no colors.
Return | |
---|---|
IntArray? |
the colors used to draw the gradient, or null |
See Also
getConstantState
open fun getConstantState(): Drawable.ConstantState?
Return | |
---|---|
Drawable.ConstantState? |
The ConstantState associated to that Drawable. This value may be null . |
getCornerRadii
open fun getCornerRadii(): FloatArray?
Returns the radii for each of the 4 corners. For each corner, the array contains 2 values, [X_radius, Y_radius]
. The corners are ordered top-left, top-right, bottom-right, bottom-left.
If the radius was previously set with setCornerRadius(float)
, or if the corners are not rounded, this method will return null
.
Return | |
---|---|
FloatArray? |
an array containing the radii for each of the 4 corners, or null |
See Also
getCornerRadius
open fun getCornerRadius(): Float
Returns the radius for the corners of the gradient, that was previously set with setCornerRadius(float)
.
If the radius was previously cleared via passing null
to setCornerRadii(float[])
, this method will return 0.
Return | |
---|---|
Float |
the radius in pixels of the corners of the rectangle shape, or 0 |
See Also
getGradientCenterX
open fun getGradientCenterX(): Float
Returns the X-position of the center of the gradient as a fraction of the width.
Return | |
---|---|
Float |
the X-position of the center of the gradient |
See Also
getGradientCenterY
open fun getGradientCenterY(): Float
Returns the Y-position of the center of this gradient as a fraction of the height.
Return | |
---|---|
Float |
the Y-position of the center of the gradient |
See Also
getGradientRadius
open fun getGradientRadius(): Float
Returns the radius of the gradient in pixels. The radius is valid only when the gradient type is set to RADIAL_GRADIENT
.
Return | |
---|---|
Float |
the radius of the gradient in pixels |
See Also
getGradientType
open fun getGradientType(): Int
Returns the type of gradient used by this drawable, one of LINEAR_GRADIENT
, RADIAL_GRADIENT
, or SWEEP_GRADIENT
.
Return | |
---|---|
Int |
the type of gradient used by this drawable Value is android.graphics.drawable.GradientDrawable#LINEAR_GRADIENT , android.graphics.drawable.GradientDrawable#RADIAL_GRADIENT , or android.graphics.drawable.GradientDrawable#SWEEP_GRADIENT |
See Also
getInnerRadius
open fun getInnerRadius(): Int
Return the inner radius of the ring
The units of this value are pixels.
Return | |
---|---|
Int |
The units of this value are pixels. {} |
See Also
getInnerRadiusRatio
open fun getInnerRadiusRatio(): Float
Return the inner radius of the ring expressed as a ratio of the ring's width.
See Also
getIntrinsicHeight
open fun getIntrinsicHeight(): Int
Return | |
---|---|
Int |
the intrinsic height, or -1 if no intrinsic height |
getIntrinsicWidth
open fun getIntrinsicWidth(): Int
Return | |
---|---|
Int |
the intrinsic width, or -1 if no intrinsic width |
getOpacity
open fun getOpacity(): Int
Return | |
---|---|
Int |
int The opacity class of the Drawable. Value is android.graphics.PixelFormat#UNKNOWN , android.graphics.PixelFormat#TRANSLUCENT , android.graphics.PixelFormat#TRANSPARENT , or android.graphics.PixelFormat#OPAQUE |
getOpticalInsets
open fun getOpticalInsets(): Insets
Return | |
---|---|
Insets |
This value cannot be null . |
getOrientation
open fun getOrientation(): GradientDrawable.Orientation!
Returns the orientation of the gradient defined in this drawable.
Return | |
---|---|
GradientDrawable.Orientation! |
the orientation of the gradient defined in this drawable |
See Also
getOutline
open fun getOutline(outline: Outline): Unit
Parameters | |
---|---|
outline |
Outline: This value cannot be null . |
getPadding
open fun getPadding(padding: Rect): Boolean
Parameters | |
---|---|
padding |
Rect: This value cannot be null . |
Return | |
---|---|
Boolean |
true if this drawable actually has a padding, else false. When false is returned, the padding is always set to 0. |
getShape
open fun getShape(): Int
Returns the type of shape used by this drawable, one of LINE
, OVAL
, RECTANGLE
or RING
.
Return | |
---|---|
Int |
the type of shape used by this drawable Value is android.graphics.drawable.GradientDrawable#RECTANGLE , android.graphics.drawable.GradientDrawable#OVAL , android.graphics.drawable.GradientDrawable#LINE , or android.graphics.drawable.GradientDrawable#RING |
See Also
getThickness
open fun getThickness(): Int
Return the thickness of the ring
The units of this value are pixels.
Return | |
---|---|
Int |
The units of this value are pixels. {} |
See Also
getThicknessRatio
open fun getThicknessRatio(): Float
Return the thickness ratio of the ring expressed as a ratio of the ring's width.
See Also
getUseLevel
open fun getUseLevel(): Boolean
Returns whether this drawable's level
property will be used to scale the gradient.
Return | |
---|---|
Boolean |
true if the gradient should be scaled based on level, false otherwise |
See Also
hasFocusStateSpecified
open fun hasFocusStateSpecified(): Boolean
Return | |
---|---|
Boolean |
true if android.R.attr#state_focused is specified for this drawable. |
inflate
open fun inflate(
r: Resources,
parser: XmlPullParser,
attrs: AttributeSet,
theme: Resources.Theme?
): Unit
Inflate this Drawable from an XML resource optionally styled by a theme. This can't be called more than once for each Drawable. Note that framework may have called this once to create the Drawable instance from XML resource.
Parameters | |
---|---|
r |
Resources: This value cannot be null . |
parser |
XmlPullParser: This value cannot be null . |
attrs |
AttributeSet: This value cannot be null . |
theme |
Resources.Theme?: This value may be null . |
Exceptions | |
---|---|
org.xmlpull.v1.XmlPullParserException |
|
java.io.IOException |
isStateful
open fun isStateful(): Boolean
Return | |
---|---|
Boolean |
True if this drawable changes its appearance based on state, false otherwise. |
mutate
open fun mutate(): Drawable
Return | |
---|---|
Drawable |
This drawable. This value cannot be null . |
setAlpha
open fun setAlpha(alpha: Int): Unit
Parameters | |
---|---|
alpha |
Int: Value is between 0 and 255 inclusive |
setColor
open fun setColor(colorStateList: ColorStateList?): Unit
Changes this drawable to use a single color state list instead of a gradient. Calling this method with a null argument will clear the color and is equivalent to calling setColor(int)
with the argument Color.TRANSPARENT
.
Note: changing color will affect all instances of a drawable loaded from a resource. It is recommended to invoke mutate()
before changing the color.
Parameters | |
---|---|
colorStateList |
ColorStateList?: The color state list used to fill the shape This value may be null . |
setColor
open fun setColor(argb: Int): Unit
Changes this drawable to use a single color instead of a gradient.
Note: changing color will affect all instances of a drawable loaded from a resource. It is recommended to invoke mutate()
before changing the color.
Parameters | |
---|---|
argb |
Int: The color used to fill the shape |
See Also
setColorFilter
open fun setColorFilter(colorFilter: ColorFilter?): Unit
Specify an optional color filter for the drawable.
If a Drawable has a ColorFilter, each output pixel of the Drawable's drawing contents will be modified by the color filter before it is blended onto the render target of a Canvas.
Pass null
to remove any existing color filter.
Note: Setting a non-null
color filter disables tint
.
Parameters | |
---|---|
colorFilter |
ColorFilter?: This value may be null . |
setColors
open fun setColors(colors: IntArray?): Unit
Sets the colors used to draw the gradient.
Each color is specified as an ARGB integer and the array must contain at least 2 colors.
Note: changing colors will affect all instances of a drawable loaded from a resource. It is recommended to invoke mutate()
before changing the colors.
Parameters | |
---|---|
colors |
IntArray?: an array containing 2 or more ARGB colors This value may be null . |
See Also
setColors
open fun setColors(
colors: IntArray?,
offsets: FloatArray?
): Unit
Sets the colors and offsets used to draw the gradient.
Each color is specified as an ARGB integer and the array must contain at least 2 colors.
Note: changing colors will affect all instances of a drawable loaded from a resource. It is recommended to invoke mutate()
before changing the colors.
Parameters | |
---|---|
colors |
IntArray?: an array containing 2 or more ARGB colors This value may be null . |
offsets |
FloatArray?: optional array of floating point parameters representing the positions of the colors. Null evenly disperses the colors This value may be null . |
See Also
setCornerRadii
open fun setCornerRadii(radii: FloatArray?): Unit
Specifies radii for each of the 4 corners. For each corner, the array contains 2 values, [X_radius, Y_radius]
. The corners are ordered top-left, top-right, bottom-right, bottom-left. This property is honored only when the shape is of type RECTANGLE
.
Note: changing this property will affect all instances of a drawable loaded from a resource. It is recommended to invoke mutate()
before changing this property.
Parameters | |
---|---|
radii |
FloatArray?: an array of length >= 8 containing 4 pairs of X and Y radius for each corner, specified in pixels This value may be null . |
setCornerRadius
open fun setCornerRadius(radius: Float): Unit
Specifies the radius for the corners of the gradient. If this is > 0, then the drawable is drawn in a round-rectangle, rather than a rectangle. This property is honored only when the shape is of type RECTANGLE
.
Note: changing this property will affect all instances of a drawable loaded from a resource. It is recommended to invoke mutate()
before changing this property.
Parameters | |
---|---|
radius |
Float: The radius in pixels of the corners of the rectangle shape |
setGradientCenter
open fun setGradientCenter(
x: Float,
y: Float
): Unit
Sets the position of the center of the gradient as a fraction of the width and height.
The default value is (0.5, 0.5).
Note: changing this property will affect all instances of a drawable loaded from a resource. It is recommended to invoke mutate()
before changing this property.
Parameters | |
---|---|
x |
Float: the X-position of the center of the gradient |
y |
Float: the Y-position of the center of the gradient |
setGradientRadius
open fun setGradientRadius(gradientRadius: Float): Unit
Sets the radius of the gradient. The radius is honored only when the gradient type is set to RADIAL_GRADIENT
.
Note: changing this property will affect all instances of a drawable loaded from a resource. It is recommended to invoke mutate()
before changing this property.
Parameters | |
---|---|
gradientRadius |
Float: the radius of the gradient in pixels |
setGradientType
open fun setGradientType(gradient: Int): Unit
Sets the type of gradient used by this drawable.
Note: changing this property will affect all instances of a drawable loaded from a resource. It is recommended to invoke mutate()
before changing this property.
Parameters | |
---|---|
gradient |
Int: The type of the gradient: LINEAR_GRADIENT , RADIAL_GRADIENT or SWEEP_GRADIENT Value is android.graphics.drawable.GradientDrawable#LINEAR_GRADIENT , android.graphics.drawable.GradientDrawable#RADIAL_GRADIENT , or android.graphics.drawable.GradientDrawable#SWEEP_GRADIENT |
See Also
setInnerRadius
open fun setInnerRadius(innerRadius: Int): Unit
Configure the inner radius of the ring.
Parameters | |
---|---|
innerRadius |
Int: The units of this value are pixels. |
See Also
setInnerRadiusRatio
open fun setInnerRadiusRatio(innerRadiusRatio: Float): Unit
Inner radius of the ring expressed as a ratio of the ring's width.
Parameters | |
---|---|
innerRadiusRatio |
Float: Value is 0.0f or greater |
See Also
setOrientation
open fun setOrientation(orientation: GradientDrawable.Orientation!): Unit
Sets the orientation of the gradient defined in this drawable.
Note: changing orientation will affect all instances of a drawable loaded from a resource. It is recommended to invoke mutate()
before changing the orientation.
Parameters | |
---|---|
orientation |
GradientDrawable.Orientation!: the desired orientation (angle) of the gradient |
See Also
setPadding
open fun setPadding(
left: Int,
top: Int,
right: Int,
bottom: Int
): Unit
Configure the padding of the gradient shape
Parameters | |
---|---|
left |
Int: Left padding of the gradient shape The units of this value are pixels. |
top |
Int: Top padding of the gradient shape The units of this value are pixels. |
right |
Int: Right padding of the gradient shape The units of this value are pixels. |
bottom |
Int: Bottom padding of the gradient shape The units of this value are pixels. |
setShape
open fun setShape(shape: Int): Unit
Sets the type of shape used to draw the gradient.
Note: changing this property will affect all instances of a drawable loaded from a resource. It is recommended to invoke mutate()
before changing this property.
Parameters | |
---|---|
shape |
Int: The desired shape for this drawable: LINE , OVAL , RECTANGLE or RING Value is android.graphics.drawable.GradientDrawable#RECTANGLE , android.graphics.drawable.GradientDrawable#OVAL , android.graphics.drawable.GradientDrawable#LINE , or android.graphics.drawable.GradientDrawable#RING |
See Also
setSize
open fun setSize(
width: Int,
height: Int
): Unit
Sets the size of the shape drawn by this drawable.
Note: changing this property will affect all instances of a drawable loaded from a resource. It is recommended to invoke mutate()
before changing this property.
Parameters | |
---|---|
width |
Int: The width of the shape used by this drawable |
height |
Int: The height of the shape used by this drawable |
See Also
setStroke
open fun setStroke(
width: Int,
colorStateList: ColorStateList!
): Unit
Set the stroke width and color state list for the drawable. If width is zero, then no stroke is drawn.
Note: changing this property will affect all instances of a drawable loaded from a resource. It is recommended to invoke mutate()
before changing this property.
Parameters | |
---|---|
width |
Int: The width in pixels of the stroke |
colorStateList |
ColorStateList!: The color state list of the stroke |
setStroke
open fun setStroke(
width: Int,
colorStateList: ColorStateList!,
dashWidth: Float,
dashGap: Float
): Unit
Set the stroke width and color state list for the drawable. If width is zero, then no stroke is drawn. This method can also be used to dash the stroke.
Note: changing this property will affect all instances of a drawable loaded from a resource. It is recommended to invoke mutate()
before changing this property.
Parameters | |
---|---|
width |
Int: The width in pixels of the stroke |
colorStateList |
ColorStateList!: The color state list of the stroke |
dashWidth |
Float: The length in pixels of the dashes, set to 0 to disable dashes |
dashGap |
Float: The gap in pixels between dashes |
See Also
setStroke
open fun setStroke(
width: Int,
color: Int
): Unit
Set the stroke width and color for the drawable. If width is zero, then no stroke is drawn.
Note: changing this property will affect all instances of a drawable loaded from a resource. It is recommended to invoke mutate()
before changing this property.
Parameters | |
---|---|
width |
Int: The width in pixels of the stroke |
color |
Int: The color of the stroke |
setStroke
open fun setStroke(
width: Int,
color: Int,
dashWidth: Float,
dashGap: Float
): Unit
Set the stroke width and color for the drawable. If width is zero, then no stroke is drawn. This method can also be used to dash the stroke.
Note: changing this property will affect all instances of a drawable loaded from a resource. It is recommended to invoke mutate()
before changing this property.
Parameters | |
---|---|
width |
Int: The width in pixels of the stroke |
color |
Int: The color of the stroke |
dashWidth |
Float: The length in pixels of the dashes, set to 0 to disable dashes |
dashGap |
Float: The gap in pixels between dashes |
See Also
setThickness
open fun setThickness(thickness: Int): Unit
Configure the thickness of the ring.
Parameters | |
---|---|
thickness |
Int: The units of this value are pixels. |
setThicknessRatio
open fun setThicknessRatio(thicknessRatio: Float): Unit
Configure the thickness of the ring expressed as a ratio of the ring's width.
Parameters | |
---|---|
thicknessRatio |
Float: Value is 0.0f or greater |
See Also
setTintBlendMode
open fun setTintBlendMode(blendMode: BlendMode!): Unit
Specifies a tint blending mode for this drawable.
Defines how this drawable's tint color should be blended into the drawable before it is drawn to screen. Default tint mode is BlendMode.SRC_IN
.
Note: Setting a color filter via setColorFilter(android.graphics.ColorFilter)
Parameters | |
---|---|
blendMode |
BlendMode!: This value cannot be null . |
setTintList
open fun setTintList(tint: ColorStateList?): Unit
Specifies tint color for this drawable as a color state list.
A Drawable's drawing content will be blended together with its tint before it is drawn to the screen. This functions similarly to setColorFilter(int,android.graphics.PorterDuff.Mode)
.
Note: Setting a color filter via setColorFilter(android.graphics.ColorFilter)
or setColorFilter(int,android.graphics.PorterDuff.Mode)
overrides tint.
Parameters | |
---|---|
tint |
ColorStateList?: This value may be null . |
setUseLevel
open fun setUseLevel(useLevel: Boolean): Unit
Sets whether this drawable's level
property will be used to scale the gradient. If a gradient is not used, this property has no effect.
Scaling behavior varies based on gradient type:
LINEAR_GRADIENT
adjusts the ending position along the gradient's axis of orientation (seegetOrientation()
)RADIAL_GRADIENT
adjusts the outer radiusSWEEP_GRADIENT
adjusts the ending angleThe default value for this property is
false
.Note: This property corresponds to the
android:useLevel
attribute on the inner<gradient>
tag, NOT theandroid:useLevel
attribute on the outer<shape>
tag. For example,<code><shape ...> <gradient ... android:useLevel="true" /> </shape> </code>
Note: Changing this property will affect all instances of a drawable loaded from a resource. It is recommended to invoke
mutate()
before changing this property.
Parameters | |
---|---|
useLevel |
Boolean: true if the gradient should be scaled based on level, false otherwise |
See Also
Protected methods
onBoundsChange
protected open fun onBoundsChange(r: Rect): Unit
Parameters | |
---|---|
bounds |
This value cannot be null . |
onLevelChange
protected open fun onLevelChange(level: Int): Boolean
Return | |
---|---|
Boolean |
Returns true if the level change has caused the appearance of the Drawable to change (that is, it needs to be drawn), else false if it looks the same and there is no need to redraw it since its last level. |
onStateChange
protected open fun onStateChange(stateSet: IntArray): Boolean
Parameters | |
---|---|
state |
This value cannot be null . |
Return | |
---|---|
Boolean |
Returns true if the state change has caused the appearance of the Drawable to change (that is, it needs to be drawn), else false if it looks the same and there is no need to redraw it since its last state. |