Package 

Class PositionableGradientDrawable


  • 
    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

    • Method Summary

      Modifier and Type Method Description
      boolean getPadding(Rect padding)
      void setCornerRadii(Array<float> radii) Specify radii for each of the 4 corners.
      void setCornerRadius(float radius) Specify radius for the corners of the gradient.
      void setStroke(int width, int color) Set the stroke width and color for the drawable.
      void setStroke(int width, ColorStateList colorStateList) Set the stroke width and color state list for the drawable.
      void setStroke(int width, int color, float dashWidth, float dashGap) Set the stroke width and color for the drawable.
      void setStroke(int width, ColorStateList colorStateList, float dashWidth, float dashGap) Set the stroke width and color state list for the drawable.
      void setSize(int width, int height) Sets the size of the shape drawn by this drawable.
      void setShape(int shape) Sets the type of shape used to draw the gradient.
      void setGradientType(int gradient) Sets the type of gradient used by this drawable..
      void setGradientCenter(float x, float y) Sets the center location of the gradient.
      void setGradientRadius(float gradientRadius) Sets the radius of the gradient.
      float getGradientRadius() Returns the radius of the gradient in pixels.
      void setUseLevel(boolean useLevel) Sets whether or not this drawable will honor its levelproperty.
      PositionableGradientDrawable.Orientation getOrientation() Returns the orientation of the gradient defined in this drawable.
      void setOrientation(PositionableGradientDrawable.Orientation orientation) Changes the orientation of the gradient defined in this drawable.
      void setColors(Array<int> colors, Array<float> positions) Sets the colors used to draw the gradient.
      void draw(Canvas canvas)
      void setColor(int argb) Changes this drawable to use a single color instead of a gradient.
      void setColor(ColorStateList colorStateList) Changes this drawable to use a single color state list instead of agradient.
      boolean isStateful()
      int getChangingConfigurations()
      void setAlpha(int alpha)
      int getAlpha()
      void setDither(boolean dither)
      ColorFilter getColorFilter()
      void setColorFilter(ColorFilter colorFilter)
      void setTintList(ColorStateList tint)
      void setTintMode(PorterDuff.Mode tintMode)
      int getOpacity()
      int getIntrinsicWidth()
      int getIntrinsicHeight()
      Drawable.ConstantState getConstantState()
      void getOutline(Outline outline)
      Drawable mutate()
      void clearMutated()
      • 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()
    • Method Detail

      • 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 stroke
        color - 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 stroke
        colorStateList - 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 stroke
        color - The color of the stroke
        dashWidth - The length in pixels of the dashes, set to 0 to disable dashes
        dashGap - 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 stroke
        colorStateList - The color state list of the stroke
        dashWidth - The length in pixels of the dashes, set to 0 to disable dashes
        dashGap - 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 drawable
        height - 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.

        Parameters:
        shape - The desired shape for this drawable: LINE,OVAL, RECTANGLE or RING
      • 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 center
        y - 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
      • 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