Known direct subclasses
ShaderBrush

Brush implementation that wraps and applies a the provided shader to a Paint The shader can be lazily created based on a given size, or provided directly as a parameter

SolidColor
Known indirect subclasses
LinearGradient

Brush implementation used to apply a linear gradient on a given Paint

RadialGradient

Brush implementation used to apply a radial gradient on a given Paint

SweepGradient

Brush implementation used to apply a sweep gradient on a given Paint


Summary

Public companion functions

Brush
horizontalGradient(
    vararg colorStops: Pair<FloatColor>,
    startX: Float,
    endX: Float,
    tileMode: TileMode
)

Creates a horizontal gradient with the given colors dispersed at the provided offset defined in the colorstop pair.

Cmn
Brush
horizontalGradient(
    colors: List<Color>,
    startX: Float,
    endX: Float,
    tileMode: TileMode
)

Creates a horizontal gradient with the given colors evenly dispersed within the gradient

Cmn
Brush
linearGradient(
    vararg colorStops: Pair<FloatColor>,
    start: Offset,
    end: Offset,
    tileMode: TileMode
)

Creates a linear gradient with the provided colors along the given start and end coordinates.

Cmn
Brush
linearGradient(
    colors: List<Color>,
    start: Offset,
    end: Offset,
    tileMode: TileMode
)

Creates a linear gradient with the provided colors along the given start and end coordinates.

Cmn
Brush
radialGradient(
    vararg colorStops: Pair<FloatColor>,
    center: Offset,
    radius: Float,
    tileMode: TileMode
)

Creates a radial gradient with the given colors at the provided offset defined in the colorstop pair.

Cmn
Brush
radialGradient(
    colors: List<Color>,
    center: Offset,
    radius: Float,
    tileMode: TileMode
)

Creates a radial gradient with the given colors evenly dispersed within the gradient

Cmn
Brush
sweepGradient(vararg colorStops: Pair<FloatColor>, center: Offset)

Creates a sweep gradient with the given colors dispersed around the center with offsets defined in each colorstop pair.

Cmn
Brush
sweepGradient(colors: List<Color>, center: Offset)

Creates a sweep gradient with the given colors dispersed evenly around the center.

Cmn
Brush
verticalGradient(
    vararg colorStops: Pair<FloatColor>,
    startY: Float,
    endY: Float,
    tileMode: TileMode
)

Creates a vertical gradient with the given colors at the provided offset defined in the Pair

Cmn
Brush
verticalGradient(
    colors: List<Color>,
    startY: Float,
    endY: Float,
    tileMode: TileMode
)

Creates a vertical gradient with the given colors evenly dispersed within the gradient Ex:

Cmn

Protected constructors

Cmn

Public functions

abstract Unit
applyTo(size: Size, p: Paint, alpha: Float)
Cmn

Public properties

open Size

Return the intrinsic size of the Brush.

Cmn

Public companion functions

horizontalGradient

fun horizontalGradient(
    vararg colorStops: Pair<FloatColor>,
    startX: Float = 0.0f,
    endX: Float = Float.POSITIVE_INFINITY,
    tileMode: TileMode = TileMode.Clamp
): Brush

Creates a horizontal gradient with the given colors dispersed at the provided offset defined in the colorstop pair.

Ex:

 Brush.horizontalGradient(
0.0f to Color.Red,
0.3f to Color.Green,
1.0f to Color.Blue,
startX = 0.0f,
endX = 100.0f
)
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color

Brush.horizontalGradient(
    0.0f to Color.Red,
    0.3f to Color.Green,
    1.0f to Color.Blue,
    startX = 0.0f,
    endX = 100.0f
)
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.wrapContentSize
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp

Column(modifier = Modifier.fillMaxSize().wrapContentSize()) {

    // Create a linear gradient that shows red in the top left corner
    // and blue in the bottom right corner
    val linear = Brush.linearGradient(listOf(Color.Red, Color.Blue))

    Box(modifier = Modifier.size(120.dp).background(linear))

    Spacer(modifier = Modifier.size(20.dp))

    // Create a radial gradient centered about the drawing area that is green on
    // the outer
    // edge of the circle and magenta towards the center of the circle
    val radial = Brush.radialGradient(listOf(Color.Green, Color.Magenta))
    Box(modifier = Modifier.size(120.dp).background(radial))

    Spacer(modifier = Modifier.size(20.dp))

    // Create a sweep gradient centered about the drawing area that is cyan at
    // the start angle and magenta towards the end angle.
    val sweep = Brush.sweepGradient(listOf(Color.Cyan, Color.Magenta))
    Box(modifier = Modifier.size(120.dp).background(sweep))
}
Parameters
vararg colorStops: Pair<FloatColor>

Colors and offsets to determine how the colors are dispersed throughout the vertical gradient

startX: Float = 0.0f

Starting x position of the horizontal gradient. Defaults to 0 which represents the left of the drawing area

endX: Float = Float.POSITIVE_INFINITY

Ending x position of the horizontal gradient. Defaults to Float.POSITIVE_INFINITY which indicates the right of the specified drawing area

tileMode: TileMode = TileMode.Clamp

Determines the behavior for how the shader is to fill a region outside its bounds. Defaults to TileMode.Clamp to repeat the edge pixels

horizontalGradient

fun horizontalGradient(
    colors: List<Color>,
    startX: Float = 0.0f,
    endX: Float = Float.POSITIVE_INFINITY,
    tileMode: TileMode = TileMode.Clamp
): Brush

Creates a horizontal gradient with the given colors evenly dispersed within the gradient

Ex:

 Brush.horizontalGradient(
listOf(Color.Red, Color.Green, Color.Blue),
startX = 10.0f,
endX = 20.0f
)
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color

Brush.horizontalGradient(
    listOf(Color.Red, Color.Green, Color.Blue),
    startX = 10.0f,
    endX = 20.0f
)
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.wrapContentSize
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp

Column(modifier = Modifier.fillMaxSize().wrapContentSize()) {

    // Create a linear gradient that shows red in the top left corner
    // and blue in the bottom right corner
    val linear = Brush.linearGradient(listOf(Color.Red, Color.Blue))

    Box(modifier = Modifier.size(120.dp).background(linear))

    Spacer(modifier = Modifier.size(20.dp))

    // Create a radial gradient centered about the drawing area that is green on
    // the outer
    // edge of the circle and magenta towards the center of the circle
    val radial = Brush.radialGradient(listOf(Color.Green, Color.Magenta))
    Box(modifier = Modifier.size(120.dp).background(radial))

    Spacer(modifier = Modifier.size(20.dp))

    // Create a sweep gradient centered about the drawing area that is cyan at
    // the start angle and magenta towards the end angle.
    val sweep = Brush.sweepGradient(listOf(Color.Cyan, Color.Magenta))
    Box(modifier = Modifier.size(120.dp).background(sweep))
}
Parameters
colors: List<Color>

colors Colors to be rendered as part of the gradient

startX: Float = 0.0f

Starting x position of the horizontal gradient. Defaults to 0 which represents the left of the drawing area

endX: Float = Float.POSITIVE_INFINITY

Ending x position of the horizontal gradient. Defaults to Float.POSITIVE_INFINITY which indicates the right of the specified drawing area

tileMode: TileMode = TileMode.Clamp

Determines the behavior for how the shader is to fill a region outside its bounds. Defaults to TileMode.Clamp to repeat the edge pixels

linearGradient

fun linearGradient(
    vararg colorStops: Pair<FloatColor>,
    start: Offset = Offset.Zero,
    end: Offset = Offset.Infinite,
    tileMode: TileMode = TileMode.Clamp
): Brush

Creates a linear gradient with the provided colors along the given start and end coordinates. The colors are dispersed at the provided offset defined in the colorstop pair.

 Brush.linearGradient(
0.0f to Color.Red,
0.3f to Color.Green,
1.0f to Color.Blue,
start = Offset(0.0f, 50.0f),
end = Offset(0.0f, 100.0f)
)
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color

Brush.linearGradient(
    0.0f to Color.Red,
    0.3f to Color.Green,
    1.0f to Color.Blue,
    start = Offset(0.0f, 50.0f),
    end = Offset(0.0f, 100.0f)
)
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.wrapContentSize
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp

Column(modifier = Modifier.fillMaxSize().wrapContentSize()) {

    // Create a linear gradient that shows red in the top left corner
    // and blue in the bottom right corner
    val linear = Brush.linearGradient(listOf(Color.Red, Color.Blue))

    Box(modifier = Modifier.size(120.dp).background(linear))

    Spacer(modifier = Modifier.size(20.dp))

    // Create a radial gradient centered about the drawing area that is green on
    // the outer
    // edge of the circle and magenta towards the center of the circle
    val radial = Brush.radialGradient(listOf(Color.Green, Color.Magenta))
    Box(modifier = Modifier.size(120.dp).background(radial))

    Spacer(modifier = Modifier.size(20.dp))

    // Create a sweep gradient centered about the drawing area that is cyan at
    // the start angle and magenta towards the end angle.
    val sweep = Brush.sweepGradient(listOf(Color.Cyan, Color.Magenta))
    Box(modifier = Modifier.size(120.dp).background(sweep))
}
Parameters
vararg colorStops: Pair<FloatColor>

Colors and their offset in the gradient area

start: Offset = Offset.Zero

Starting position of the linear gradient. This can be set to Offset.Zero to position at the far left and top of the drawing area

end: Offset = Offset.Infinite

Ending position of the linear gradient. This can be set to Offset.Infinite to position at the far right and bottom of the drawing area

tileMode: TileMode = TileMode.Clamp

Determines the behavior for how the shader is to fill a region outside its bounds. Defaults to TileMode.Clamp to repeat the edge pixels

linearGradient

fun linearGradient(
    colors: List<Color>,
    start: Offset = Offset.Zero,
    end: Offset = Offset.Infinite,
    tileMode: TileMode = TileMode.Clamp
): Brush

Creates a linear gradient with the provided colors along the given start and end coordinates. The colors are

 Brush.linearGradient(
listOf(Color.Red, Color.Green, Color.Blue),
start = Offset(0.0f, 50.0f),
end = Offset(0.0f, 100.0f)
)
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color

Brush.linearGradient(
    listOf(Color.Red, Color.Green, Color.Blue),
    start = Offset(0.0f, 50.0f),
    end = Offset(0.0f, 100.0f)
)
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.wrapContentSize
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp

Column(modifier = Modifier.fillMaxSize().wrapContentSize()) {

    // Create a linear gradient that shows red in the top left corner
    // and blue in the bottom right corner
    val linear = Brush.linearGradient(listOf(Color.Red, Color.Blue))

    Box(modifier = Modifier.size(120.dp).background(linear))

    Spacer(modifier = Modifier.size(20.dp))

    // Create a radial gradient centered about the drawing area that is green on
    // the outer
    // edge of the circle and magenta towards the center of the circle
    val radial = Brush.radialGradient(listOf(Color.Green, Color.Magenta))
    Box(modifier = Modifier.size(120.dp).background(radial))

    Spacer(modifier = Modifier.size(20.dp))

    // Create a sweep gradient centered about the drawing area that is cyan at
    // the start angle and magenta towards the end angle.
    val sweep = Brush.sweepGradient(listOf(Color.Cyan, Color.Magenta))
    Box(modifier = Modifier.size(120.dp).background(sweep))
}
Parameters
colors: List<Color>

Colors to be rendered as part of the gradient

start: Offset = Offset.Zero

Starting position of the linear gradient. This can be set to Offset.Zero to position at the far left and top of the drawing area

end: Offset = Offset.Infinite

Ending position of the linear gradient. This can be set to Offset.Infinite to position at the far right and bottom of the drawing area

tileMode: TileMode = TileMode.Clamp

Determines the behavior for how the shader is to fill a region outside its bounds. Defaults to TileMode.Clamp to repeat the edge pixels

radialGradient

fun radialGradient(
    vararg colorStops: Pair<FloatColor>,
    center: Offset = Offset.Unspecified,
    radius: Float = Float.POSITIVE_INFINITY,
    tileMode: TileMode = TileMode.Clamp
): Brush

Creates a radial gradient with the given colors at the provided offset defined in the colorstop pair.

Brush.radialGradient(
0.0f to Color.Red,
0.3f to Color.Green,
1.0f to Color.Blue,
center = Offset(side1 / 2.0f, side2 / 2.0f),
radius = side1 / 2.0f,
tileMode = TileMode.Repeated
)
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.TileMode

val side1 = 100
val side2 = 200
Brush.radialGradient(
    0.0f to Color.Red,
    0.3f to Color.Green,
    1.0f to Color.Blue,
    center = Offset(side1 / 2.0f, side2 / 2.0f),
    radius = side1 / 2.0f,
    tileMode = TileMode.Repeated
)
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.wrapContentSize
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp

Column(modifier = Modifier.fillMaxSize().wrapContentSize()) {

    // Create a linear gradient that shows red in the top left corner
    // and blue in the bottom right corner
    val linear = Brush.linearGradient(listOf(Color.Red, Color.Blue))

    Box(modifier = Modifier.size(120.dp).background(linear))

    Spacer(modifier = Modifier.size(20.dp))

    // Create a radial gradient centered about the drawing area that is green on
    // the outer
    // edge of the circle and magenta towards the center of the circle
    val radial = Brush.radialGradient(listOf(Color.Green, Color.Magenta))
    Box(modifier = Modifier.size(120.dp).background(radial))

    Spacer(modifier = Modifier.size(20.dp))

    // Create a sweep gradient centered about the drawing area that is cyan at
    // the start angle and magenta towards the end angle.
    val sweep = Brush.sweepGradient(listOf(Color.Cyan, Color.Magenta))
    Box(modifier = Modifier.size(120.dp).background(sweep))
}
Parameters
vararg colorStops: Pair<FloatColor>

Colors and offsets to determine how the colors are dispersed throughout the radial gradient

center: Offset = Offset.Unspecified

Center position of the radial gradient circle. If this is set to Offset.Unspecified then the center of the drawing area is used as the center for the radial gradient. Float.POSITIVE_INFINITY can be used for either Offset.x or Offset.y to indicate the far right or far bottom of the drawing area respectively.

radius: Float = Float.POSITIVE_INFINITY

Radius for the radial gradient. Defaults to positive infinity to indicate the largest radius that can fit within the bounds of the drawing area

tileMode: TileMode = TileMode.Clamp

Determines the behavior for how the shader is to fill a region outside its bounds. Defaults to TileMode.Clamp to repeat the edge pixels

radialGradient

fun radialGradient(
    colors: List<Color>,
    center: Offset = Offset.Unspecified,
    radius: Float = Float.POSITIVE_INFINITY,
    tileMode: TileMode = TileMode.Clamp
): Brush

Creates a radial gradient with the given colors evenly dispersed within the gradient

Brush.radialGradient(
listOf(Color.Red, Color.Green, Color.Blue),
center = Offset(side1 / 2.0f, side2 / 2.0f),
radius = side1 / 2.0f,
tileMode = TileMode.Repeated
)
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.TileMode

val side1 = 100
val side2 = 200
Brush.radialGradient(
    listOf(Color.Red, Color.Green, Color.Blue),
    center = Offset(side1 / 2.0f, side2 / 2.0f),
    radius = side1 / 2.0f,
    tileMode = TileMode.Repeated
)
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.wrapContentSize
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp

Column(modifier = Modifier.fillMaxSize().wrapContentSize()) {

    // Create a linear gradient that shows red in the top left corner
    // and blue in the bottom right corner
    val linear = Brush.linearGradient(listOf(Color.Red, Color.Blue))

    Box(modifier = Modifier.size(120.dp).background(linear))

    Spacer(modifier = Modifier.size(20.dp))

    // Create a radial gradient centered about the drawing area that is green on
    // the outer
    // edge of the circle and magenta towards the center of the circle
    val radial = Brush.radialGradient(listOf(Color.Green, Color.Magenta))
    Box(modifier = Modifier.size(120.dp).background(radial))

    Spacer(modifier = Modifier.size(20.dp))

    // Create a sweep gradient centered about the drawing area that is cyan at
    // the start angle and magenta towards the end angle.
    val sweep = Brush.sweepGradient(listOf(Color.Cyan, Color.Magenta))
    Box(modifier = Modifier.size(120.dp).background(sweep))
}
Parameters
colors: List<Color>

Colors to be rendered as part of the gradient

center: Offset = Offset.Unspecified

Center position of the radial gradient circle. If this is set to Offset.Unspecified then the center of the drawing area is used as the center for the radial gradient. Float.POSITIVE_INFINITY can be used for either Offset.x or Offset.y to indicate the far right or far bottom of the drawing area respectively.

radius: Float = Float.POSITIVE_INFINITY

Radius for the radial gradient. Defaults to positive infinity to indicate the largest radius that can fit within the bounds of the drawing area

tileMode: TileMode = TileMode.Clamp

Determines the behavior for how the shader is to fill a region outside its bounds. Defaults to TileMode.Clamp to repeat the edge pixels

sweepGradient

fun sweepGradient(
    vararg colorStops: Pair<FloatColor>,
    center: Offset = Offset.Unspecified
): Brush

Creates a sweep gradient with the given colors dispersed around the center with offsets defined in each colorstop pair. The sweep begins relative to 3 o'clock and continues clockwise until it reaches the starting position again.

Ex:

 Brush.sweepGradient(
0.0f to Color.Red,
0.3f to Color.Green,
1.0f to Color.Blue,
center = Offset(0.0f, 100.0f)
)
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color

Brush.sweepGradient(
    0.0f to Color.Red,
    0.3f to Color.Green,
    1.0f to Color.Blue,
    center = Offset(0.0f, 100.0f)
)
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.wrapContentSize
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp

Column(modifier = Modifier.fillMaxSize().wrapContentSize()) {

    // Create a linear gradient that shows red in the top left corner
    // and blue in the bottom right corner
    val linear = Brush.linearGradient(listOf(Color.Red, Color.Blue))

    Box(modifier = Modifier.size(120.dp).background(linear))

    Spacer(modifier = Modifier.size(20.dp))

    // Create a radial gradient centered about the drawing area that is green on
    // the outer
    // edge of the circle and magenta towards the center of the circle
    val radial = Brush.radialGradient(listOf(Color.Green, Color.Magenta))
    Box(modifier = Modifier.size(120.dp).background(radial))

    Spacer(modifier = Modifier.size(20.dp))

    // Create a sweep gradient centered about the drawing area that is cyan at
    // the start angle and magenta towards the end angle.
    val sweep = Brush.sweepGradient(listOf(Color.Cyan, Color.Magenta))
    Box(modifier = Modifier.size(120.dp).background(sweep))
}
Parameters
vararg colorStops: Pair<FloatColor>

Colors and offsets to determine how the colors are dispersed throughout the sweep gradient

center: Offset = Offset.Unspecified

Center position of the sweep gradient circle. If this is set to Offset.Unspecified then the center of the drawing area is used as the center for the sweep gradient

sweepGradient

fun sweepGradient(colors: List<Color>, center: Offset = Offset.Unspecified): Brush

Creates a sweep gradient with the given colors dispersed evenly around the center. The sweep begins relative to 3 o'clock and continues clockwise until it reaches the starting position again.

Ex:

 Brush.sweepGradient(
listOf(Color.Red, Color.Green, Color.Blue),
center = Offset(10.0f, 20.0f)
)
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color

Brush.sweepGradient(listOf(Color.Red, Color.Green, Color.Blue), center = Offset(10.0f, 20.0f))
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.wrapContentSize
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp

Column(modifier = Modifier.fillMaxSize().wrapContentSize()) {

    // Create a linear gradient that shows red in the top left corner
    // and blue in the bottom right corner
    val linear = Brush.linearGradient(listOf(Color.Red, Color.Blue))

    Box(modifier = Modifier.size(120.dp).background(linear))

    Spacer(modifier = Modifier.size(20.dp))

    // Create a radial gradient centered about the drawing area that is green on
    // the outer
    // edge of the circle and magenta towards the center of the circle
    val radial = Brush.radialGradient(listOf(Color.Green, Color.Magenta))
    Box(modifier = Modifier.size(120.dp).background(radial))

    Spacer(modifier = Modifier.size(20.dp))

    // Create a sweep gradient centered about the drawing area that is cyan at
    // the start angle and magenta towards the end angle.
    val sweep = Brush.sweepGradient(listOf(Color.Cyan, Color.Magenta))
    Box(modifier = Modifier.size(120.dp).background(sweep))
}
Parameters
colors: List<Color>

List of colors to fill the sweep gradient

center: Offset = Offset.Unspecified

Center position of the sweep gradient circle. If this is set to Offset.Unspecified then the center of the drawing area is used as the center for the sweep gradient

verticalGradient

fun verticalGradient(
    vararg colorStops: Pair<FloatColor>,
    startY: Float = 0.0f,
    endY: Float = Float.POSITIVE_INFINITY,
    tileMode: TileMode = TileMode.Clamp
): Brush

Creates a vertical gradient with the given colors at the provided offset defined in the Pair

Ex:

 Brush.verticalGradient(
0.1f to Color.Red,
0.3f to Color.Green,
0.5f to Color.Blue,
startY = 0.0f,
endY = 100.0f
)
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color

Brush.verticalGradient(
    0.1f to Color.Red,
    0.3f to Color.Green,
    0.5f to Color.Blue,
    startY = 0.0f,
    endY = 100.0f
)
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.wrapContentSize
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp

Column(modifier = Modifier.fillMaxSize().wrapContentSize()) {

    // Create a linear gradient that shows red in the top left corner
    // and blue in the bottom right corner
    val linear = Brush.linearGradient(listOf(Color.Red, Color.Blue))

    Box(modifier = Modifier.size(120.dp).background(linear))

    Spacer(modifier = Modifier.size(20.dp))

    // Create a radial gradient centered about the drawing area that is green on
    // the outer
    // edge of the circle and magenta towards the center of the circle
    val radial = Brush.radialGradient(listOf(Color.Green, Color.Magenta))
    Box(modifier = Modifier.size(120.dp).background(radial))

    Spacer(modifier = Modifier.size(20.dp))

    // Create a sweep gradient centered about the drawing area that is cyan at
    // the start angle and magenta towards the end angle.
    val sweep = Brush.sweepGradient(listOf(Color.Cyan, Color.Magenta))
    Box(modifier = Modifier.size(120.dp).background(sweep))
}
Parameters
vararg colorStops: Pair<FloatColor>

Colors and offsets to determine how the colors are dispersed throughout the vertical gradient

startY: Float = 0.0f

Starting y position of the vertical gradient. Defaults to 0 which represents the top of the drawing area

endY: Float = Float.POSITIVE_INFINITY

Ending y position of the vertical gradient. Defaults to Float.POSITIVE_INFINITY which indicates the bottom of the specified drawing area

tileMode: TileMode = TileMode.Clamp

Determines the behavior for how the shader is to fill a region outside its bounds. Defaults to TileMode.Clamp to repeat the edge pixels

verticalGradient

fun verticalGradient(
    colors: List<Color>,
    startY: Float = 0.0f,
    endY: Float = Float.POSITIVE_INFINITY,
    tileMode: TileMode = TileMode.Clamp
): Brush

Creates a vertical gradient with the given colors evenly dispersed within the gradient Ex:

 Brush.verticalGradient(
listOf(Color.Red, Color.Green, Color.Blue),
startY = 0.0f,
endY = 100.0f
)
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color

Brush.verticalGradient(listOf(Color.Red, Color.Green, Color.Blue), startY = 0.0f, endY = 100.0f)
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.wrapContentSize
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp

Column(modifier = Modifier.fillMaxSize().wrapContentSize()) {

    // Create a linear gradient that shows red in the top left corner
    // and blue in the bottom right corner
    val linear = Brush.linearGradient(listOf(Color.Red, Color.Blue))

    Box(modifier = Modifier.size(120.dp).background(linear))

    Spacer(modifier = Modifier.size(20.dp))

    // Create a radial gradient centered about the drawing area that is green on
    // the outer
    // edge of the circle and magenta towards the center of the circle
    val radial = Brush.radialGradient(listOf(Color.Green, Color.Magenta))
    Box(modifier = Modifier.size(120.dp).background(radial))

    Spacer(modifier = Modifier.size(20.dp))

    // Create a sweep gradient centered about the drawing area that is cyan at
    // the start angle and magenta towards the end angle.
    val sweep = Brush.sweepGradient(listOf(Color.Cyan, Color.Magenta))
    Box(modifier = Modifier.size(120.dp).background(sweep))
}
Parameters
colors: List<Color>

colors Colors to be rendered as part of the gradient

startY: Float = 0.0f

Starting y position of the vertical gradient. Defaults to 0 which represents the top of the drawing area

endY: Float = Float.POSITIVE_INFINITY

Ending y position of the vertical gradient. Defaults to Float.POSITIVE_INFINITY which indicates the bottom of the specified drawing area

tileMode: TileMode = TileMode.Clamp

Determines the behavior for how the shader is to fill a region outside its bounds. Defaults to TileMode.Clamp to repeat the edge pixels

Protected constructors

Brush

protected Brush()

Public functions

applyTo

abstract fun applyTo(size: Size, p: Paint, alpha: Float): Unit

Public properties

intrinsicSize

open val intrinsicSizeSize

Return the intrinsic size of the Brush. If the there is no intrinsic size (i.e. filling bounds with an arbitrary color) return Size.Unspecified. If there is no intrinsic size in a single dimension, return Size with Float.NaN in the desired dimension.