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

Brush.Companion

public static class Brush.Companion


Summary

Public methods

static final @NonNull Brush
horizontalGradient(
    @NonNull Pair<@NonNull Float, @NonNull Color> colorStops,
    float startX,
    float endX,
    @NonNull TileMode tileMode
)

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

static final @NonNull Brush
horizontalGradient(
    @NonNull List<@NonNull Color> colors,
    float startX,
    float endX,
    @NonNull TileMode tileMode
)

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

static final @NonNull Brush
linearGradient(
    @NonNull Pair<@NonNull Float, @NonNull Color> colorStops,
    @NonNull Offset start,
    @NonNull Offset end,
    @NonNull TileMode tileMode
)

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

static final @NonNull Brush
linearGradient(
    @NonNull List<@NonNull Color> colors,
    @NonNull Offset start,
    @NonNull Offset end,
    @NonNull TileMode tileMode
)

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

static final @NonNull Brush
radialGradient(
    @NonNull Pair<@NonNull Float, @NonNull Color> colorStops,
    @NonNull Offset center,
    float radius,
    @NonNull TileMode tileMode
)

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

static final @NonNull Brush
radialGradient(
    @NonNull List<@NonNull Color> colors,
    @NonNull Offset center,
    float radius,
    @NonNull TileMode tileMode
)

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

static final @NonNull Brush
sweepGradient(
    @NonNull Pair<@NonNull Float, @NonNull Color> colorStops,
    @NonNull Offset center
)

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

static final @NonNull Brush

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

static final @NonNull Brush
verticalGradient(
    @NonNull Pair<@NonNull Float, @NonNull Color> colorStops,
    float startY,
    float endY,
    @NonNull TileMode tileMode
)

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

static final @NonNull Brush
verticalGradient(
    @NonNull List<@NonNull Color> colors,
    float startY,
    float endY,
    @NonNull TileMode tileMode
)

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

Public methods

horizontalGradient

public static final @NonNull Brush horizontalGradient(
    @NonNull Pair<@NonNull Float, @NonNull Color> colorStops,
    float startX,
    float endX,
    @NonNull TileMode tileMode
)

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 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 sweep = Brush.sweepGradient(listOf(Color.Cyan, Color.Magenta))
    Box(modifier = Modifier.size(120.dp).background(sweep))
}
Parameters
@NonNull Pair<@NonNull Float, @NonNull Color> colorStops

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

float startX

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

float endX

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

@NonNull TileMode tileMode

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

public static final @NonNull Brush horizontalGradient(
    @NonNull List<@NonNull Color> colors,
    float startX,
    float endX,
    @NonNull TileMode tileMode
)

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 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 sweep = Brush.sweepGradient(listOf(Color.Cyan, Color.Magenta))
    Box(modifier = Modifier.size(120.dp).background(sweep))
}
Parameters
@NonNull List<@NonNull Color> colors

colors Colors to be rendered as part of the gradient

float startX

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

float endX

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

@NonNull TileMode tileMode

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

public static final @NonNull Brush linearGradient(
    @NonNull Pair<@NonNull Float, @NonNull Color> colorStops,
    @NonNull Offset start,
    @NonNull Offset end,
    @NonNull TileMode tileMode
)

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 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 sweep = Brush.sweepGradient(listOf(Color.Cyan, Color.Magenta))
    Box(modifier = Modifier.size(120.dp).background(sweep))
}
Parameters
@NonNull Pair<@NonNull Float, @NonNull Color> colorStops

Colors and their offset in the gradient area

@NonNull Offset start

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

@NonNull Offset end

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

@NonNull TileMode tileMode

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

public static final @NonNull Brush linearGradient(
    @NonNull List<@NonNull Color> colors,
    @NonNull Offset start,
    @NonNull Offset end,
    @NonNull TileMode tileMode
)

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 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 sweep = Brush.sweepGradient(listOf(Color.Cyan, Color.Magenta))
    Box(modifier = Modifier.size(120.dp).background(sweep))
}
Parameters
@NonNull List<@NonNull Color> colors

Colors to be rendered as part of the gradient

@NonNull Offset start

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

@NonNull Offset end

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

@NonNull TileMode tileMode

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

public static final @NonNull Brush radialGradient(
    @NonNull Pair<@NonNull Float, @NonNull Color> colorStops,
    @NonNull Offset center,
    float radius,
    @NonNull TileMode tileMode
)

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 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 sweep = Brush.sweepGradient(listOf(Color.Cyan, Color.Magenta))
    Box(modifier = Modifier.size(120.dp).background(sweep))
}
Parameters
@NonNull Pair<@NonNull Float, @NonNull Color> colorStops

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

@NonNull Offset center

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.

float radius

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

@NonNull TileMode tileMode

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

public static final @NonNull Brush radialGradient(
    @NonNull List<@NonNull Color> colors,
    @NonNull Offset center,
    float radius,
    @NonNull TileMode tileMode
)

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 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 sweep = Brush.sweepGradient(listOf(Color.Cyan, Color.Magenta))
    Box(modifier = Modifier.size(120.dp).background(sweep))
}
Parameters
@NonNull List<@NonNull Color> colors

Colors to be rendered as part of the gradient

@NonNull Offset center

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.

float radius

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

@NonNull TileMode tileMode

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

public static final @NonNull Brush sweepGradient(
    @NonNull Pair<@NonNull Float, @NonNull Color> colorStops,
    @NonNull Offset center
)

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 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 sweep = Brush.sweepGradient(listOf(Color.Cyan, Color.Magenta))
    Box(modifier = Modifier.size(120.dp).background(sweep))
}
Parameters
@NonNull Pair<@NonNull Float, @NonNull Color> colorStops

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

@NonNull Offset center

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

public static final @NonNull Brush sweepGradient(@NonNull List<@NonNull Color> colors, @NonNull Offset center)

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 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 sweep = Brush.sweepGradient(listOf(Color.Cyan, Color.Magenta))
    Box(modifier = Modifier.size(120.dp).background(sweep))
}
Parameters
@NonNull List<@NonNull Color> colors

List of colors to fill the sweep gradient

@NonNull Offset center

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

public static final @NonNull Brush verticalGradient(
    @NonNull Pair<@NonNull Float, @NonNull Color> colorStops,
    float startY,
    float endY,
    @NonNull TileMode tileMode
)

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 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 sweep = Brush.sweepGradient(listOf(Color.Cyan, Color.Magenta))
    Box(modifier = Modifier.size(120.dp).background(sweep))
}
Parameters
@NonNull Pair<@NonNull Float, @NonNull Color> colorStops

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

float startY

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

float endY

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

@NonNull TileMode tileMode

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

public static final @NonNull Brush verticalGradient(
    @NonNull List<@NonNull Color> colors,
    float startY,
    float endY,
    @NonNull TileMode tileMode
)

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 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 sweep = Brush.sweepGradient(listOf(Color.Cyan, Color.Magenta))
    Box(modifier = Modifier.size(120.dp).background(sweep))
}
Parameters
@NonNull List<@NonNull Color> colors

colors Colors to be rendered as part of the gradient

float startY

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

float endY

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

@NonNull TileMode tileMode

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