My application needs a ProgressBar, and I am trying to implement it with Jetpack Compose, so either I need a builtin ProgressBar support (I didn't find it) or there should be a mechanism to display plain Android Widgets with Compose. Is anything of this possible?
6 Answers
Ofcourse, we have Progress Bars in Jetpack Compose:
CircularProgressIndicator: Displays progress bar as Circle. It is indeterminate. Themed to Primary color set in styles. Another variant is determinate that takes progress in argument as Float (0.0f - 1.0f)
Example:
// Indeterminate
CircularProgressIndicator()
// Determinate
CircularProgressIndicator(progress = 0.5f)
LinearProgressIndicator: Displays progress bar as line. It is indeterminate. Themed to Primary color set in styles. Another variant is determinate that takes progress in argument as Float (0.0f - 1.0f)
Example:
// Indeterminate
LinearProgressIndicator()
// Determinate
LinearProgressIndicator(progress = 0.5f)

- 24,761
- 25
- 106
- 174
-
What is the valid way to modify the progress of indicator? Effect
>? – Commander Tvis Jan 22 '20 at 14:53 -
how to make corners rounded? – Mirza Ahmed Baig Mar 09 '21 at 15:27
-
adjusting corner radius on this should be much easier – Kyle Mar 25 '21 at 15:34
-
1@MirzaAhmedBaig doesn't look like it's possible unless you wanna do a bunch of stuff with Shape – Kyle Mar 25 '21 at 15:59
-
1Small comment - the first example has a typo: it is missing an s :D Thanks for this answer. – Yoel Gluschnaider Jun 27 '21 at 09:42
-
Can you provide an example on how we can call this composable methods from a simple button onClick listener? Because all I get is an error "@Composable invocations can only happen from the context of a @Composable function". Thank you!! – Pavlos Mavris Mar 13 '23 at 15:34
With 1.0.x
you can use the LinearProgressIndicator
or CircularProgressIndicator
// Indeterminate
CircularProgressIndicator()
LinearProgressIndicator()
// Determinate
CircularProgressIndicator(progress = ..)
LinearProgressIndicator(progress = ..)
Example:
var progress by remember { mutableStateOf(0.1f) }
LinearProgressIndicator(
backgroundColor = Color.White,
progress = progress,
color = blue700
)
To update the value you can use something like:
// { if (progress < 1f) progress += 0.1f }

- 320,139
- 94
- 887
- 841
-
2
-
-
-
@Tanjimahmed Just use a boolean: `if (isVisible) { LinearProgressIndicator()} ` – Gabriele Mariotti Sep 14 '21 at 07:58
For rounded corners we can use this code (It's the same like LinearProgress but with one small correction - in drawLine we use param StrokeCap.Round for rounding)
@Composable
fun LinearRoundedProgressIndicator(
/*@FloatRange(from = 0.0, to = 1.0)*/
progress: Float,
modifier: Modifier = Modifier,
color: Color = MaterialTheme.colors.primary,
backgroundColor: Color = color.copy(alpha = ProgressIndicatorDefaults.IndicatorBackgroundOpacity)
) {
val linearIndicatorHeight = ProgressIndicatorDefaults.StrokeWidth
val linearIndicatorWidth = 240.dp
Canvas(
modifier
.progressSemantics(progress)
.size(linearIndicatorWidth, linearIndicatorHeight)
.focusable()
) {
val strokeWidth = size.height
drawRoundedLinearIndicatorBackground(backgroundColor, strokeWidth)
drawRoundedLinearIndicator(0f, progress, color, strokeWidth)
}
}
private fun DrawScope.drawRoundedLinearIndicatorBackground(
color: Color,
strokeWidth: Float
) = drawRoundedLinearIndicator(0f, 1f, color, strokeWidth)
private fun DrawScope.drawRoundedLinearIndicator(
startFraction: Float,
endFraction: Float,
color: Color,
strokeWidth: Float
) {
val width = size.width
val height = size.height
// Start drawing from the vertical center of the stroke
val yOffset = height / 2
val isLtr = layoutDirection == LayoutDirection.Ltr
val barStart = (if (isLtr) startFraction else 1f - endFraction) * width
val barEnd = (if (isLtr) endFraction else 1f - startFraction) * width
// Progress line
drawLine(color, Offset(barStart, yOffset), Offset(barEnd, yOffset), strokeWidth, StrokeCap.Round)
}

- 543
- 5
- 16
-
1Make sure you use the import androidx.compose.foundation.Canvas import if you're running into issues. – Bharadwaj Giridhar Sep 08 '21 at 15:24
custom linear progress indicator
@Composable
fun CustomLinearProgressIndicator(
modifier: Modifier = Modifier,
progress: Float,
progressColor: Color = orangeColor,
backgroundColor: Color = orangeColor.copy(0.24f),
clipShape: Shape = RoundedCornerShape(16.dp)
) {
Box(
modifier = modifier
.clip(clipShape)
.background(backgroundColor)
.height(8.dp)
) {
Box(
modifier = Modifier
.background(progressColor)
.fillMaxHeight()
.fillMaxWidth(progress)
)
}
}

- 775
- 5
- 12
For someone who is looking for a rounded corner linear progress bar, you can use the Modifier's clip function.
LinearProgressIndicator(
progress = 0.5f,
modifier = Modifier.height(10.dp).clip(RoundedCornerShape(10.dp))
)

- 56
- 3
you can use this library which supports thumb, round corners, and animations. https://github.com/KevinnZou/compose-progressIndicator

- 11
- 1
-
As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Oct 15 '22 at 14:29
-
While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/late-answers/32922877) – Vojin Purić Oct 17 '22 at 07:09