{% setvar book_path %}/reference/androidx/_book.yaml{% endsetvar %} {% include "_shared/_reference-head-tags.html" %}

ShaderKt

public final class ShaderKt


Summary

Public methods

static final @NonNull Shader
ImageShader(
    @NonNull ImageBitmap image,
    @NonNull TileMode tileModeX,
    @NonNull TileMode tileModeY
)

Creates a Shader using the given ImageBitmap as an input texture.

static final @NonNull Shader
LinearGradientShader(
    @NonNull Offset from,
    @NonNull Offset to,
    @NonNull List<@NonNull Color> colors,
    List<@NonNull Float> colorStops,
    @NonNull TileMode tileMode
)

Creates a linear gradient from from to to.

static final @NonNull Shader
RadialGradientShader(
    @NonNull Offset center,
    float radius,
    @NonNull List<@NonNull Color> colors,
    List<@NonNull Float> colorStops,
    @NonNull TileMode tileMode
)

Creates a radial gradient centered at center that ends at radius distance from the center.

static final @NonNull Shader
SweepGradientShader(
    @NonNull Offset center,
    @NonNull List<@NonNull Color> colors,
    List<@NonNull Float> colorStops
)

Creates a circular gradient that sweeps around a provided center point.

Public methods

ImageShader

public static final @NonNull Shader ImageShader(
    @NonNull ImageBitmap image,
    @NonNull TileMode tileModeX,
    @NonNull TileMode tileModeY
)

Creates a Shader using the given ImageBitmap as an input texture. If the shader is to be drawn in an area larger than the size of the ImageBitmap, the region is filled in the horizontal and vertical directions based on the tileModeX and tileModeY parameters.

LinearGradientShader

public static final @NonNull Shader LinearGradientShader(
    @NonNull Offset from,
    @NonNull Offset to,
    @NonNull List<@NonNull Color> colors,
    List<@NonNull Float> colorStops,
    @NonNull TileMode tileMode
)

Creates a linear gradient from from to to.

If colorStops is provided, each value is a number from 0.0 to 1.0 that specifies where the color at the corresponding index in colors begins in the gradient. If colorStops is not provided, then the colors are dispersed evenly

The behavior before from and after to is described by the tileMode argument. For details, see the TileMode enum. If no TileMode is provided the default value of TileMode.Clamp is used

RadialGradientShader

public static final @NonNull Shader RadialGradientShader(
    @NonNull Offset center,
    float radius,
    @NonNull List<@NonNull Color> colors,
    List<@NonNull Float> colorStops,
    @NonNull TileMode tileMode
)

Creates a radial gradient centered at center that ends at radius distance from the center.

If colorStops is provided, each value is a number from 0.0 to 1.0 that specifies where the color at the corresponding index in colors begins in the gradient. If colorStops is not provided, then the colors are dispersed evenly

The behavior before and after the radius is described by the tileMode argument. For details, see the TileMode enum.

The behavior outside of the bounds of center +/- radius is described by the tileMode argument. For details, see the TileMode enum. If no TileMode is provided the default value of TileMode.Clamp is used

SweepGradientShader

public static final @NonNull Shader SweepGradientShader(
    @NonNull Offset center,
    @NonNull List<@NonNull Color> colors,
    List<@NonNull Float> colorStops
)

Creates a circular gradient that sweeps around a provided center point. The sweep begins relative to 3 o'clock and continues clockwise until it reaches the starting position again.

If colorStops is provided, each value is a number from 0.0 to 1.0 that specifies where the color at the corresponding index in colors begins in the gradient. If colorStops is not provided, then the colors are dispersed evenly

Parameters
@NonNull Offset center

Position for the gradient to sweep around

@NonNull List<@NonNull Color> colors

Colors to be rendered as part of the gradient

List<@NonNull Float> colorStops

Placement of the colors along the sweep about the center position