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

AndroidPaint

public final class AndroidPaint implements Paint


Create a Compose Paint instance backed by an android.graphics.Paint object to be consumed by Compose applications running on the Android platform

Summary

Public constructors

Create a new AndroidPaint instance backed by a newly created android.graphics.Paint

AndroidPaint(@NonNull Paint internalPaint)

Public methods

@NonNull Paint
float

Configures the alpha value between 0f to 1f representing fully transparent to fully opaque for the color drawn with this Paint

@NonNull BlendMode

A blend mode to apply when a shape is drawn or a layer is composited.

@NonNull Color

The color to use when stroking or filling a shape.

ColorFilter

A color filter to apply when a shape is drawn or when a layer is composited.

@NonNull FilterQuality

Controls the performance vs quality trade-off to use when applying when drawing images, as with Canvas.drawImageRect Defaults to FilterQuality.Low.

PathEffect

Specifies the PathEffect applied to the geometry of the shape that is drawn

Shader

The shader to use when stroking or filling a shape.

@NonNull StrokeCap

The kind of finish to place on the end of lines drawn when style is set to PaintingStyle.Stroke.

@NonNull StrokeJoin

The kind of finish to place on the joins between segments.

float

The limit for miters to be drawn on segments when the join is set to StrokeJoin.Miter and the style is set to PaintingStyle.Stroke.

float

How wide to make edges drawn when style is set to PaintingStyle.Stroke.

@NonNull PaintingStyle

Whether to paint inside shapes, the edges of shapes, or both.

boolean

Whether to apply anti-aliasing to lines and images drawn on the canvas.

void
setAlpha(float alpha)

Configures the alpha value between 0f to 1f representing fully transparent to fully opaque for the color drawn with this Paint

void
setAntiAlias(boolean isAntiAlias)

Whether to apply anti-aliasing to lines and images drawn on the canvas.

void

A blend mode to apply when a shape is drawn or a layer is composited.

void

The color to use when stroking or filling a shape.

void

A color filter to apply when a shape is drawn or when a layer is composited.

void

Controls the performance vs quality trade-off to use when applying when drawing images, as with Canvas.drawImageRect Defaults to FilterQuality.Low.

void

Specifies the PathEffect applied to the geometry of the shape that is drawn

void
setShader(Shader shader)

The shader to use when stroking or filling a shape.

void

The kind of finish to place on the end of lines drawn when style is set to PaintingStyle.Stroke.

void

The kind of finish to place on the joins between segments.

void
setStrokeMiterLimit(float strokeMiterLimit)

The limit for miters to be drawn on segments when the join is set to StrokeJoin.Miter and the style is set to PaintingStyle.Stroke.

void
setStrokeWidth(float strokeWidth)

How wide to make edges drawn when style is set to PaintingStyle.Stroke.

void

Whether to paint inside shapes, the edges of shapes, or both.

Public constructors

AndroidPaint

public AndroidPaint()

Create a new AndroidPaint instance backed by a newly created android.graphics.Paint

AndroidPaint

public AndroidPaint(@NonNull Paint internalPaint)
Parameters
@NonNull Paint internalPaint

android.graphics.Paint to be wrapped by the AndroidPaint instance

Public methods

asFrameworkPaint

public @NonNull Paint asFrameworkPaint()

getAlpha

public float getAlpha()

Configures the alpha value between 0f to 1f representing fully transparent to fully opaque for the color drawn with this Paint

getBlendMode

public @NonNull BlendMode getBlendMode()

A blend mode to apply when a shape is drawn or a layer is composited. The source colors are from the shape being drawn (e.g. from Canvas.drawPath) or layer being composited (the graphics that were drawn between the Canvas.saveLayer and Canvas.restore calls), after applying the colorFilter, if any. The destination colors are from the background onto which the shape or layer is being composited. Defaults to BlendMode.SrcOver. See also: Canvas.saveLayer, which uses its Paint's blendMode to composite the layer when Canvas.restore is called. BlendMode, which discusses the user of Canvas.saveLayer with blendMode.

getColor

public @NonNull Color getColor()

The color to use when stroking or filling a shape. Defaults to opaque black. See also: style, which controls whether to stroke or fill (or both). colorFilter, which overrides color. shader, which overrides color with more elaborate effects. This color is not used when compositing. To colorize a layer, use colorFilter.

getColorFilter

public ColorFilter getColorFilter()

A color filter to apply when a shape is drawn or when a layer is composited. See ColorFilter for details. When a shape is being drawn, colorFilter overrides color and shader.

getFilterQuality

public @NonNull FilterQuality getFilterQuality()

Controls the performance vs quality trade-off to use when applying when drawing images, as with Canvas.drawImageRect Defaults to FilterQuality.Low.

getPathEffect

public PathEffect getPathEffect()

Specifies the PathEffect applied to the geometry of the shape that is drawn

getShader

public Shader getShader()

The shader to use when stroking or filling a shape.

When this is null, the color is used instead.

See also: LinearGradientShader, RadialGradientShader, or SweepGradientShader shaders that paint a color gradient. ImageShader, a shader that tiles an ImageBitmap. colorFilter, which overrides shader. color, which is used if shader and colorFilter are null.

getStrokeCap

public @NonNull StrokeCap getStrokeCap()

The kind of finish to place on the end of lines drawn when style is set to PaintingStyle.Stroke. Defaults to StrokeCap.Butt, i.e. no caps.

getStrokeJoin

public @NonNull StrokeJoin getStrokeJoin()

The kind of finish to place on the joins between segments. This applies to paths drawn when style is set to PaintingStyle.Stroke, It does not apply to points drawn as lines with Canvas.drawPoints. Defaults to StrokeJoin.Miter, i.e. sharp corners. See also strokeMiterLimit to control when miters are replaced by bevels.

getStrokeMiterLimit

public float getStrokeMiterLimit()

The limit for miters to be drawn on segments when the join is set to StrokeJoin.Miter and the style is set to PaintingStyle.Stroke. If this limit is exceeded, then a StrokeJoin.Bevel join will be drawn instead. This may cause some 'popping' of the corners of a path if the angle between line segments is animated. This limit is expressed as a limit on the length of the miter. Defaults to 4.0. Using zero as a limit will cause a StrokeJoin.Bevel join to be used all the time.

getStrokeWidth

public float getStrokeWidth()

How wide to make edges drawn when style is set to PaintingStyle.Stroke. The width is given in logical pixels measured in the direction orthogonal to the direction of the path. Defaults to 0.0, which correspond to a hairline width.

getStyle

public @NonNull PaintingStyle getStyle()

Whether to paint inside shapes, the edges of shapes, or both. Defaults to PaintingStyle.Fill.

isAntiAlias

public boolean isAntiAlias()

Whether to apply anti-aliasing to lines and images drawn on the canvas. Defaults to true.

setAlpha

public void setAlpha(float alpha)

Configures the alpha value between 0f to 1f representing fully transparent to fully opaque for the color drawn with this Paint

setAntiAlias

public void setAntiAlias(boolean isAntiAlias)

Whether to apply anti-aliasing to lines and images drawn on the canvas. Defaults to true.

setBlendMode

public void setBlendMode(@NonNull BlendMode blendMode)

A blend mode to apply when a shape is drawn or a layer is composited. The source colors are from the shape being drawn (e.g. from Canvas.drawPath) or layer being composited (the graphics that were drawn between the Canvas.saveLayer and Canvas.restore calls), after applying the colorFilter, if any. The destination colors are from the background onto which the shape or layer is being composited. Defaults to BlendMode.SrcOver. See also: Canvas.saveLayer, which uses its Paint's blendMode to composite the layer when Canvas.restore is called. BlendMode, which discusses the user of Canvas.saveLayer with blendMode.

setColor

public void setColor(@NonNull Color color)

The color to use when stroking or filling a shape. Defaults to opaque black. See also: style, which controls whether to stroke or fill (or both). colorFilter, which overrides color. shader, which overrides color with more elaborate effects. This color is not used when compositing. To colorize a layer, use colorFilter.

setColorFilter

public void setColorFilter(ColorFilter colorFilter)

A color filter to apply when a shape is drawn or when a layer is composited. See ColorFilter for details. When a shape is being drawn, colorFilter overrides color and shader.

setFilterQuality

public void setFilterQuality(@NonNull FilterQuality filterQuality)

Controls the performance vs quality trade-off to use when applying when drawing images, as with Canvas.drawImageRect Defaults to FilterQuality.Low.

setPathEffect

public void setPathEffect(PathEffect pathEffect)

Specifies the PathEffect applied to the geometry of the shape that is drawn

setShader

public void setShader(Shader shader)

The shader to use when stroking or filling a shape.

When this is null, the color is used instead.

See also: LinearGradientShader, RadialGradientShader, or SweepGradientShader shaders that paint a color gradient. ImageShader, a shader that tiles an ImageBitmap. colorFilter, which overrides shader. color, which is used if shader and colorFilter are null.

setStrokeCap

public void setStrokeCap(@NonNull StrokeCap strokeCap)

The kind of finish to place on the end of lines drawn when style is set to PaintingStyle.Stroke. Defaults to StrokeCap.Butt, i.e. no caps.

setStrokeJoin

public void setStrokeJoin(@NonNull StrokeJoin strokeJoin)

The kind of finish to place on the joins between segments. This applies to paths drawn when style is set to PaintingStyle.Stroke, It does not apply to points drawn as lines with Canvas.drawPoints. Defaults to StrokeJoin.Miter, i.e. sharp corners. See also strokeMiterLimit to control when miters are replaced by bevels.

setStrokeMiterLimit

public void setStrokeMiterLimit(float strokeMiterLimit)

The limit for miters to be drawn on segments when the join is set to StrokeJoin.Miter and the style is set to PaintingStyle.Stroke. If this limit is exceeded, then a StrokeJoin.Bevel join will be drawn instead. This may cause some 'popping' of the corners of a path if the angle between line segments is animated. This limit is expressed as a limit on the length of the miter. Defaults to 4.0. Using zero as a limit will cause a StrokeJoin.Bevel join to be used all the time.

setStrokeWidth

public void setStrokeWidth(float strokeWidth)

How wide to make edges drawn when style is set to PaintingStyle.Stroke. The width is given in logical pixels measured in the direction orthogonal to the direction of the path. Defaults to 0.0, which correspond to a hairline width.

setStyle

public void setStyle(@NonNull PaintingStyle style)

Whether to paint inside shapes, the edges of shapes, or both. Defaults to PaintingStyle.Fill.