@ComposablefunLinearDeterminateIndicator(){varcurrentProgressbyremember{mutableStateOf(0f)}varloadingbyremember{mutableStateOf(false)}valscope=rememberCoroutineScope()// Create a coroutine scopeColumn(verticalArrangement=Arrangement.spacedBy(12.dp),horizontalAlignment=Alignment.CenterHorizontally,modifier=Modifier.fillMaxWidth()){Button(onClick={loading=truescope.launch{loadProgress{progress->
currentProgress=progress}loading=false// Reset loading when the coroutine finishes}},enabled=!loading){Text("Start loading")}if(loading){LinearProgressIndicator(progress={currentProgress},modifier=Modifier.fillMaxWidth(),)}}}/** Iterate the progress value */suspendfunloadProgress(updateProgress:(Float)->Unit){for(iin1..100){updateProgress(i.toFloat()/100)delay(100)}}
[null,null,["最后更新时间 (UTC):2025-08-25。"],[],[],null,["# Progress indicators visually surface the status of an operation. They use motion\nto bring to the user's attention how near completion the process is, such as\nloading or processing data. They can also signify that processing is taking\nplace, without reference to how close to completion it might be.\n\nConsider these three use cases where you might use a progress indicator:\n\n- **Loading content**: While fetching content from a network, such as loading an image or data for a user profile.\n- **File upload**: Give the user feedback on how long the upload might take.\n- **Long processing**: While an app is processing a large amount of data, convey to the user how much of the total is complete.\n\nIn Material Design, there are two types of progress indicator:\n\n- **Determinate**: Displays exactly how much progress has been made.\n- **Indeterminate**: Animates continually without regard to progress.\n\nLikewise, a progress indicator can take one of the two following forms:\n\n- **Linear**: A horizontal bar that fills from left to right.\n- **Circular**: A circle whose stroke grows in length until it encompasses the full circumference of the circle.\n\n**Figure 1.** The two types of progress indicators.\n\nAPI Surface\n-----------\n\nAlthough there are several composables you can use to create progress indicators\nconsistent with Material Design, their parameters don't differ greatly. Among\nthe key parameters you should keep in mind are the following:\n\n- `progress`: The current progress that the indicator displays. Pass a `Float` between `0.0` and `1.0`.\n- `color`: The color of the actual indicator. That is, the part of the component that reflects progress and which fully encompasses the component when progress is complete.\n- `trackColor`: The color of the track over which the indicator is drawn.\n\n| **Note:** The APIs for `LinearProgressIndicator` and `CircularProgressIndicator` are essentially the same and the way you use either one is identical. You can use the following snippets for either.\n\nDeterminate indicators\n----------------------\n\nA determinate indicator reflects exactly how complete an action is. Use either\nthe [`LinearProgressIndicator`](/reference/com/google/android/material/progressindicator/LinearProgressIndicator) or [`CircularProgressIndicator`](/reference/com/google/android/material/progressindicator/CircularProgressIndicator)\ncomposables and pass a value for the `progress` parameter.\n\nThe following snippet provides a relatively detailed example. When the user\npresses the button, the app both displays the progress indicator, and launches a\ncoroutine that gradually increases the value of `progress`. This causes the\nprogress indicator to iterate up in turn.\n| **Note:** The following example uses a coroutine to do the work of iterating the `progress` value because it would otherwise block the UI thread.\n\n\n```kotlin\n@Composable\nfun LinearDeterminateIndicator() {\n var currentProgress by remember { mutableStateOf(0f) }\n var loading by remember { mutableStateOf(false) }\n val scope = rememberCoroutineScope() // Create a coroutine scope\n\n Column(\n verticalArrangement = Arrangement.spacedBy(12.dp),\n horizontalAlignment = Alignment.CenterHorizontally,\n modifier = Modifier.fillMaxWidth()\n ) {\n Button(onClick = {\n loading = true\n scope.launch {\n loadProgress { progress -\u003e\n currentProgress = progress\n }\n loading = false // Reset loading when the coroutine finishes\n }\n }, enabled = !loading) {\n Text(\"Start loading\")\n }\n\n if (loading) {\n LinearProgressIndicator(\n progress = { currentProgress },\n modifier = Modifier.fillMaxWidth(),\n )\n }\n }\n}\n\n/** Iterate the progress value */\nsuspend fun loadProgress(updateProgress: (Float) -\u003e Unit) {\n for (i in 1..100) {\n updateProgress(i.toFloat() / 100)\n delay(100)\n }\n}https://github.com/android/snippets/blob/dd30aee903e8c247786c064faab1a9ca8d10b46e/compose/snippets/src/main/java/com/example/compose/snippets/components/ProgressIndicator.kt#L66-L104\n```\n\n\u003cbr /\u003e\n\nWhen loading is partially complete, the linear indicator in the preceding\nexample appears as follows:\n\nLikewise, the circular indicator appears as follows:\n\nIndeterminate indicators\n------------------------\n\nAn indeterminate indicator does not reflect how close to completion an operation\nis. Rather, it uses motion to indicate to the user that processing is ongoing,\nthough without specifying any degree of completion.\n\nTo create an indeterminate progress indicator, use the `LinearProgressIndicator`\nor `CircularProgressIndicator` composable, but don't pass in a value for\n`progress`. The following example demonstrates how you can toggle an\nindeterminate indicator with a button press.\n| **Note:** This example also demonstrates how you can pass values for the `color` and `trackColor` parameters to customize the appearance of the indicator.\n\n\n```kotlin\n@Composable\nfun IndeterminateCircularIndicator() {\n var loading by remember { mutableStateOf(false) }\n\n Button(onClick = { loading = true }, enabled = !loading) {\n Text(\"Start loading\")\n }\n\n if (!loading) return\n\n CircularProgressIndicator(\n modifier = Modifier.width(64.dp),\n color = MaterialTheme.colorScheme.secondary,\n trackColor = MaterialTheme.colorScheme.surfaceVariant,\n )\n}https://github.com/android/snippets/blob/dd30aee903e8c247786c064faab1a9ca8d10b46e/compose/snippets/src/main/java/com/example/compose/snippets/components/ProgressIndicator.kt#L160-L175\n```\n\n\u003cbr /\u003e\n\nThe following is an example of this implementation when the indicator is active:\n\nThe following is an example of the same implementation but with\n`LinearProgressIndicator` instead of `CircularProgressIndicator`.\n\nAdditional resources\n--------------------\n\n- [Material UI docs](https://m3.material.io/components/progress-indicators/overview)"]]