How to show Circular Progress Indicator in Android Jetpack Compose

By Mohammed Rashid •  September 4th, 2022 • 

Progress indicators are very useful UI elements to show the progress of any kind of action. In this blog post, let’s learn how to add a circular progress indicator in Jetpack Compose.

CircularProgressIndicator composable helps to show circular progress indicators in Jetpack Compose. Following is the code snippet of the indeterminate circular progress indicator.

@Composable
fun ProgressIndicator(){
    Column{
        CircularProgressIndicator(
                modifier = Modifier
                    .size(100.dp),
                color = Color.Red,
                strokeWidth = 10.dp
            )
    }
}

You can also make the progress indicator determinate using the progress parameter.

Following is the complete code.

package com.example.example
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.*
import androidx.compose.material.*
import androidx.compose.runtime.*
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.example.example.ui.theme.ExampleTheme

class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            ExampleTheme {
                // A surface container using the 'background' color from the theme
                Surface(
                    modifier = Modifier.fillMaxSize(),
                    color = MaterialTheme.colors.background
                ) {
                    ProgressIndicator()
                }
            }
        }
    }
}

@Preview(showBackground = true)
@Composable
fun ProgressIndicator(){
    Column{
        CircularProgressIndicator(
                modifier = Modifier
                    .size(100.dp),
                color = Color.Red,
                strokeWidth = 10.dp
            )
    }
}


@Preview(showBackground = true)
@Composable
fun DefaultPreview() {
    ExampleTheme {
        ProgressIndicator()
    }
}

Following is the output.

That’s how you add a circular progress indicator in Jetpack Compose.

Mohammed Rashid

Keep Reading