با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
نشانگرهای پیشرفت به صورت بصری وضعیت یک عملیات را نشان می دهند. آنها از حرکت استفاده می کنند تا توجه کاربر را جلب کنند که فرآیند نزدیک به اتمام است، مانند بارگیری یا پردازش داده ها. آنها همچنین می توانند نشان دهند که پردازش در حال انجام است، بدون اشاره به اینکه چقدر ممکن است به اتمام برسد.
این سه مورد استفاده را در نظر بگیرید که ممکن است از نشانگر پیشرفت استفاده کنید:
بارگیری محتوا : هنگام واکشی محتوا از شبکه، مانند بارگیری یک تصویر یا داده برای نمایه کاربر.
آپلود فایل : بازخورد کاربر را در مورد مدت زمان آپلود ارائه دهید.
پردازش طولانی : در حالی که یک برنامه در حال پردازش حجم زیادی از داده ها است، به کاربر اطلاع دهید که چه مقدار از کل داده ها کامل شده است.
قطعه زیر یک مثال نسبتاً مفصل ارائه می دهد. وقتی کاربر دکمه را فشار میدهد، برنامه هم نشانگر پیشرفت را نشان میدهد و هم برنامهای را راهاندازی میکند که به تدریج ارزش progress را افزایش میدهد. این باعث می شود که نشانگر پیشرفت به نوبه خود تکرار شود.
نتایج
هنگامی که بارگیری تا حدی کامل شد، نشانگر خطی در مثال قبل به صورت زیر ظاهر می شود:
به همین ترتیب، نشانگر دایره ای به صورت زیر ظاهر می شود:
ایجاد شاخص های نامشخص
یک شاخص نامشخص نشان نمی دهد که یک عملیات چقدر به اتمام نزدیک است. در عوض، از حرکت استفاده می کند تا به کاربر نشان دهد که پردازش در حال انجام است، البته بدون تعیین درجه ای از تکمیل.
برای ایجاد یک نشانگر پیشرفت نامشخص، از LinearProgressIndicator یا CircularProgressIndicator قابل ترکیب استفاده کنید، اما مقداری را برای progress ارسال نکنید. مثال زیر نشان می دهد که چگونه می توانید یک نشانگر نامشخص را با فشار دادن دکمه تغییر دهید.
نتایج
در زیر نمونه ای از این پیاده سازی زمانی که اندیکاتور فعال است نشان داده شده است:
نمونه زیر نمونه ای از همین پیاده سازی است اما با LinearProgressIndicator به جای CircularProgressIndicator .
نکات کلیدی
اگرچه چندین ترکیب وجود دارد که می توانید برای ایجاد شاخص های پیشرفت مطابق با طراحی متریال از آنها استفاده کنید، پارامترهای آنها تفاوت زیادی با هم ندارند. از جمله پارامترهای کلیدی که باید در نظر داشته باشید موارد زیر است:
progress : پیشرفت فعلی که نشانگر نمایش می دهد. عبور از یک Float بین 0.0 و 1.0 .
color : رنگ نشانگر، یعنی بخشی از مؤلفه که پیشرفت را منعکس می کند و هنگامی که پیشرفت کامل شد، جزء را کاملاً در بر می گیرد.
trackColor : رنگ مسیری که نشانگر روی آن کشیده شده است.
مجموعه هایی که حاوی این راهنما هستند
این راهنما بخشی از مجموعههای راهنمای Quick Guide است که اهداف توسعه Android گستردهتری را پوشش میدهد:
نمایش اجزای تعاملی
بیاموزید که چگونه توابع ترکیبپذیر میتوانند به شما کمک کنند تا به راحتی اجزای رابط کاربری زیبا را بر اساس سیستم طراحی مواد طراحی کنید.
محتوا و نمونه کدها در این صفحه مشمول پروانههای توصیفشده در پروانه محتوا هستند. جاوا و OpenJDK علامتهای تجاری یا علامتهای تجاری ثبتشده Oracle و/یا وابستههای آن هستند.
تاریخ آخرین بهروزرسانی 2025-02-06 بهوقت ساعت هماهنگ جهانی.
[[["درک آسان","easyToUnderstand","thumb-up"],["مشکلم را برطرف کرد","solvedMyProblem","thumb-up"],["غیره","otherUp","thumb-up"]],[["اطلاعاتی که نیاز دارم وجود ندارد","missingTheInformationINeed","thumb-down"],["بیشازحد پیچیده/ مراحل بسیار زیاد","tooComplicatedTooManySteps","thumb-down"],["قدیمی","outOfDate","thumb-down"],["مشکل ترجمه","translationIssue","thumb-down"],["مشکل کد / نمونهها","samplesCodeIssue","thumb-down"],["غیره","otherDown","thumb-down"]],["تاریخ آخرین بهروزرسانی 2025-02-06 بهوقت ساعت هماهنگ جهانی."],[],[],null,["# Create a progress indicator\n\n\u003cbr /\u003e\n\nProgress 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](#determinate): Displays exactly how much progress has been made.\n- [Indeterminate](#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\nVersion compatibility\n---------------------\n\nThis implementation requires that your project minSDK be set to API level 21 or\nhigher.\n\n### Dependencies\n\n### Kotlin\n\n\u003cbr /\u003e\n\n```kotlin\n implementation(platform(\"androidx.compose:compose-bom:2025.08.00\"))\n \n```\n\n\u003cbr /\u003e\n\n### Groovy\n\n\u003cbr /\u003e\n\n```groovy\n implementation platform('androidx.compose:compose-bom:2025.08.00')\n \n```\n\n\u003cbr /\u003e\n\nCreate determinate indicators\n-----------------------------\n\nA determinate indicator reflects exactly how complete an action is. Use either\nthe [`LinearProgressIndicator`](/reference/kotlin/androidx/compose/material3/package-summary#LinearProgressIndicator(androidx.compose.ui.Modifier,androidx.compose.ui.graphics.Color,androidx.compose.ui.graphics.Color,androidx.compose.ui.graphics.StrokeCap,androidx.compose.ui.unit.Dp)) or [`CircularProgressIndicator`](/reference/kotlin/androidx/compose/material3/package-summary#CircularProgressIndicator(androidx.compose.ui.Modifier,androidx.compose.ui.graphics.Color,androidx.compose.ui.unit.Dp,androidx.compose.ui.graphics.Color,androidx.compose.ui.graphics.StrokeCap,androidx.compose.ui.unit.Dp))\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\u003cbr /\u003e\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}\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\n\u003cbr /\u003e\n\n### Results\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\nCreate indeterminate 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\u003cbr /\u003e\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}\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\n\u003cbr /\u003e\n\n### Results\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\nKey points\n----------\n\nAlthough there are several composables you can use to create progress indicators\nconsistent with Material Design, their parameters don't differ greatly.\nAmong the 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 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.\n\nCollections that contain this guide\n-----------------------------------\n\nThis guide is part of these curated Quick Guide collections that cover\nbroader Android development goals: \n\n### Display interactive components\n\nLearn how composable functions can enable you to easily create beautiful UI components based on the Material Design design system. \n[Quick guide collection](/develop/ui/compose/quick-guides/collections/display-interactive-components) \n\n### Display a list or grid\n\nLists and grids allow your app to display collections in a visually pleasing form that's easy for users to consume. \n[Quick guide collection](/develop/ui/compose/quick-guides/collections/display-a-list-or-grid) \n\nHave questions or feedback\n--------------------------\n\nGo to our frequently asked questions page and learn about quick guides or reach out and let us know your thoughts. \n[Go to FAQ](/quick-guides/faq) [Leave feedback](https://issuetracker.google.com/issues/new?component=1573691&template=1993320)"]]