-
public class PositionableGradientDrawable extends Drawable
A Drawable with a color gradient for buttons, backgrounds, etc.
Tweaked for Batch: No XML support, added support for setting the color positions Tinting is also broken, due to private APIs
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public enumPositionableGradientDrawable.OrientationControls how the gradient is oriented relative to the drawable's bounds
-
Field Summary
Fields Modifier and Type Field Description public final static intRECTANGLEpublic final static intOVALpublic final static intLINEpublic final static intRINGpublic final static intLINEAR_GRADIENTpublic final static intRADIAL_GRADIENTpublic final static intSWEEP_GRADIENT
-
Constructor Summary
Constructors Constructor Description PositionableGradientDrawable()PositionableGradientDrawable(PositionableGradientDrawable.Orientation orientation, Array<int> colors, Array<float> positions)Create a new gradient drawable given an orientation and an arrayof colors for the gradient.
-
Method Summary
Modifier and Type Method Description booleangetPadding(Rect padding)voidsetCornerRadii(Array<float> radii)Specify radii for each of the 4 corners. voidsetCornerRadius(float radius)Specify radius for the corners of the gradient. voidsetStroke(int width, int color)Set the stroke width and color for the drawable. voidsetStroke(int width, ColorStateList colorStateList)Set the stroke width and color state list for the drawable. voidsetStroke(int width, int color, float dashWidth, float dashGap)Set the stroke width and color for the drawable. voidsetStroke(int width, ColorStateList colorStateList, float dashWidth, float dashGap)Set the stroke width and color state list for the drawable. voidsetSize(int width, int height)Sets the size of the shape drawn by this drawable. voidsetShape(int shape)Sets the type of shape used to draw the gradient. voidsetGradientType(int gradient)Sets the type of gradient used by this drawable.. voidsetGradientCenter(float x, float y)Sets the center location of the gradient. voidsetGradientRadius(float gradientRadius)Sets the radius of the gradient. floatgetGradientRadius()Returns the radius of the gradient in pixels. voidsetUseLevel(boolean useLevel)Sets whether or not this drawable will honor its levelproperty.PositionableGradientDrawable.OrientationgetOrientation()Returns the orientation of the gradient defined in this drawable. voidsetOrientation(PositionableGradientDrawable.Orientation orientation)Changes the orientation of the gradient defined in this drawable. voidsetColors(Array<int> colors, Array<float> positions)Sets the colors used to draw the gradient. voiddraw(Canvas canvas)voidsetColor(int argb)Changes this drawable to use a single color instead of a gradient. voidsetColor(ColorStateList colorStateList)Changes this drawable to use a single color state list instead of agradient. booleanisStateful()intgetChangingConfigurations()voidsetAlpha(int alpha)intgetAlpha()voidsetDither(boolean dither)ColorFiltergetColorFilter()voidsetColorFilter(ColorFilter colorFilter)voidsetTintList(ColorStateList tint)voidsetTintMode(PorterDuff.Mode tintMode)intgetOpacity()intgetIntrinsicWidth()intgetIntrinsicHeight()Drawable.ConstantStategetConstantState()voidgetOutline(Outline outline)Drawablemutate()voidclearMutated()-
Methods inherited from class android.graphics.drawable.Drawable
applyTheme, canApplyTheme, clearColorFilter, copyBounds, copyBounds, createFromPath, createFromResourceStream, createFromStream, createFromXml, createFromXmlInner, draw, getAlpha, getBounds, getCallback, getChangingConfigurations, getColorFilter, getConstantState, getCurrent, getDirtyBounds, getHotspotBounds, getIntrinsicHeight, getIntrinsicWidth, getLayoutDirection, getLevel, getMinimumHeight, getMinimumWidth, getOpacity, getOpticalInsets, getOutline, getPadding, getState, getTransparentRegion, hasFocusStateSpecified, inflate, invalidateSelf, isAutoMirrored, isFilterBitmap, isProjected, isStateful, isVisible, jumpToCurrentState, mutate, onLayoutDirectionChanged, resolveOpacity, scheduleSelf, setAlpha, setAutoMirrored, setBounds, setCallback, setChangingConfigurations, setColorFilter, setDither, setFilterBitmap, setHotspot, setHotspotBounds, setLayoutDirection, setLevel, setState, setTint, setTintBlendMode, setTintList, setTintMode, setVisible, unscheduleSelf -
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
Constructor Detail
-
PositionableGradientDrawable
PositionableGradientDrawable()
-
PositionableGradientDrawable
PositionableGradientDrawable(PositionableGradientDrawable.Orientation orientation, Array<int> colors, Array<float> positions)
Create a new gradient drawable given an orientation and an arrayof colors for the gradient.
-
-
Method Detail
-
getPadding
boolean getPadding(Rect padding)
-
setCornerRadii
void setCornerRadii(Array<float> radii)
Specify radii for each of the 4 corners. For each corner, the arraycontains 2 values,
[X_radius, Y_radius]. The corners are orderedtop-left, top-right, bottom-right, bottom-left. This propertyis honored only when the shape is of type RECTANGLE.Note: changing this property will affect all instancesof a drawable loaded from a resource. It is recommended to invoke mutate before changing this property.
- Parameters:
radii- 4 pairs of X and Y radius for each corner, specified in pixels.
-
setCornerRadius
void setCornerRadius(float radius)
Specify radius for the corners of the gradient. If this is > 0, then thedrawable is drawn in a round-rectangle, rather than a rectangle. This propertyis honored only when the shape is of type RECTANGLE.
Note: changing this property will affect all instancesof a drawable loaded from a resource. It is recommended to invoke mutate before changing this property.
- Parameters:
radius- The radius in pixels of the corners of the rectangle shape
-
setStroke
void setStroke(int width, int color)
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 instancesof a drawable loaded from a resource. It is recommended to invoke mutate before changing this property.
- Parameters:
width- The width in pixels of the strokecolor- The color of the stroke
-
setStroke
void setStroke(int width, ColorStateList colorStateList)
Set the stroke width and color state list for the drawable. If widthis zero, then no stroke is drawn.
Note: changing this property will affect all instancesof a drawable loaded from a resource. It is recommended to invoke mutate before changing this property.
- Parameters:
width- The width in pixels of the strokecolorStateList- The color state list of the stroke
-
setStroke
void setStroke(int width, int color, float dashWidth, float dashGap)
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 instancesof a drawable loaded from a resource. It is recommended to invoke mutate before changing this property.
- Parameters:
width- The width in pixels of the strokecolor- The color of the strokedashWidth- The length in pixels of the dashes, set to 0 to disable dashesdashGap- The gap in pixels between dashes
-
setStroke
void setStroke(int width, ColorStateList colorStateList, float dashWidth, float dashGap)
Set the stroke width and color state list for the drawable. If widthis zero, then no stroke is drawn. This method can also be used to dashthe stroke.
Note: changing this property will affect all instancesof a drawable loaded from a resource. It is recommended to invoke mutate before changing this property.
- Parameters:
width- The width in pixels of the strokecolorStateList- The color state list of the strokedashWidth- The length in pixels of the dashes, set to 0 to disable dashesdashGap- The gap in pixels between dashes
-
setSize
void setSize(int width, int height)
Sets the size of the shape drawn by this drawable.
Note: changing this property will affect all instancesof a drawable loaded from a resource. It is recommended to invoke mutate before changing this property.
- Parameters:
width- The width of the shape used by this drawableheight- The height of the shape used by this drawable
-
setShape
void setShape(int shape)
Sets the type of shape used to draw the gradient.
Note: changing this property will affect all instancesof a drawable loaded from a resource. It is recommended to invoke mutate before changing this property.
-
setGradientType
void setGradientType(int gradient)
Sets the type of gradient used by this drawable..
Note: changing this property will affect all instancesof a drawable loaded from a resource. It is recommended to invoke mutate before changing this property.
- Parameters:
gradient- The type of the gradient: LINEAR_GRADIENT,RADIAL_GRADIENT or SWEEP_GRADIENT
-
setGradientCenter
void setGradientCenter(float x, float y)
Sets the center location of the gradient. The radius is honored only whenthe gradient type is set to RADIAL_GRADIENT or SWEEP_GRADIENT.
Note: changing this property will affect all instancesof a drawable loaded from a resource. It is recommended to invoke mutate before changing this property.
- Parameters:
x- The x coordinate of the gradient's centery- The y coordinate of the gradient's center
-
setGradientRadius
void setGradientRadius(float gradientRadius)
Sets the radius of the gradient. The radius is honored only when thegradient type is set to RADIAL_GRADIENT.
Note: changing this property will affect all instancesof a drawable loaded from a resource. It is recommended to invoke mutate before changing this property.
- Parameters:
gradientRadius- The radius of the gradient in pixels
-
getGradientRadius
float getGradientRadius()
Returns the radius of the gradient in pixels. The radius is valid onlywhen the gradient type is set to RADIAL_GRADIENT.
-
setUseLevel
void setUseLevel(boolean useLevel)
Sets whether or not this drawable will honor its
levelproperty.Note: changing this property will affect all instancesof a drawable loaded from a resource. It is recommended to invoke mutate before changing this property.
- Parameters:
useLevel- True if this drawable should honor its level, false otherwise
-
getOrientation
PositionableGradientDrawable.Orientation getOrientation()
Returns the orientation of the gradient defined in this drawable.
-
setOrientation
void setOrientation(PositionableGradientDrawable.Orientation orientation)
Changes the orientation of the gradient defined in this drawable.
Note: changing orientation will affect all instancesof a drawable loaded from a resource. It is recommended to invoke mutate before changing the orientation.
- Parameters:
orientation- The desired orientation (angle) of the gradient
-
setColors
void setColors(Array<int> colors, Array<float> positions)
Sets the colors used to draw the gradient.
Each color is specified as an ARGB integer and the array must contain atleast 2 colors.
Note: changing colors will affect all instances of adrawable loaded from a resource. It is recommended to invoke mutate before changing the colors.
- Parameters:
colors- an array containing 2 or more ARGB colors
-
setColor
void setColor(int argb)
Changes this drawable to use a single color instead of a gradient.
Note: changing color will affect all instancesof a drawable loaded from a resource. It is recommended to invoke mutate before changing the color.
- Parameters:
argb- The color used to fill the shape
-
setColor
void setColor(ColorStateList colorStateList)
Changes this drawable to use a single color state list instead of agradient. Calling this method with a null argument will clear the colorand is equivalent to calling setColor with the argument TRANSPARENT.
Note: changing color will affect all instances of adrawable loaded from a resource. It is recommended to invoke mutate before changing the color.
- Parameters:
colorStateList- The color state list used to fill the shape
-
isStateful
boolean isStateful()
-
getChangingConfigurations
int getChangingConfigurations()
-
setAlpha
void setAlpha(int alpha)
-
getAlpha
int getAlpha()
-
setDither
void setDither(boolean dither)
-
getColorFilter
ColorFilter getColorFilter()
-
setColorFilter
void setColorFilter(ColorFilter colorFilter)
-
setTintList
void setTintList(ColorStateList tint)
-
setTintMode
void setTintMode(PorterDuff.Mode tintMode)
-
getOpacity
int getOpacity()
-
getIntrinsicWidth
int getIntrinsicWidth()
-
getIntrinsicHeight
int getIntrinsicHeight()
-
getConstantState
Drawable.ConstantState getConstantState()
-
getOutline
void getOutline(Outline outline)
-
clearMutated
void clearMutated()
-
-
-
-