0Pricing
Jetpack Compose Academy · Lesson

Enabled, Disabled & Loading States

Reflect availability in your buttons.

Enabled, Disabled & Loading States is a free Jetpack Compose Academy lesson on CoddyKit — lesson 3 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Jetpack Compose Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Buttons Have Moods

A good button reflects reality: ready, blocked, or working. Compose lets you express these states so users always know what is possible. 🚦

The enabled Parameter

Every button takes an enabled flag. Set it to false and the button greys out and ignores taps automatically.

Button(
    onClick = { submit() },
    enabled = false
) { Text("Submit") }

Drive enabled From State

The real power is binding enabled to state. Tie it to validation so the button only activates when input is ready.

Button(
    onClick = { submit() },
    enabled = name.isNotBlank()
) { Text("Submit") }

Disabled Means Blocked

A disabled button still appears, so users see the action exists. Its faded look signals why not yet without an error message.

Show Progress While Working

For slow actions, show a loading state. Track a boolean and swap the label for a spinner while the work runs.

var loading by remember { mutableStateOf(false) }

Disable During Loading

While loading, set enabled = !loading so users cannot double-tap and fire the same action twice.

Button(
    onClick = { loading = true },
    enabled = !loading
) { Text("Save") }

Swap In a Spinner

Inside the content, branch on the flag: show a small CircularProgressIndicator when loading, the label otherwise.

Button(onClick = { }, enabled = !loading) {
    if (loading) CircularProgressIndicator(Modifier.size(18.dp))
    else Text("Save")
}

Size the Spinner Down

The default spinner is large. Constrain it with a Modifier.size so it fits neatly where the label used to sit.

CircularProgressIndicator(
    modifier = Modifier.size(18.dp),
    strokeWidth = 2.dp
)

Reset When Done

When the work finishes, set loading back to false. The label returns and the button becomes tappable again.

onResult = { loading = false }

States Prevent Mistakes

Together, enabled and loading guard your actions: no taps before input is valid, no duplicate taps while work is in flight.

Communicate, Don't Hide

Prefer disabling over hiding a button. A visible-but-disabled control teaches users the path to unlock it.

Quick Check

Your save action takes two seconds and users keep double-tapping it.

Recap: Stateful Buttons

You learned to reflect reality: enabled gates by validity, a loading flag shows progress and blocks repeats. Honest buttons, happy users. 🎯

Frequently asked questions

Is the “Enabled, Disabled & Loading States” lesson free?

Yes — the full text of “Enabled, Disabled & Loading States” is free to read here on the web, and the Jetpack Compose Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Jetpack Compose Academy course, upgrade to CoddyKit PRO.

What will I learn in “Enabled, Disabled & Loading States”?

Reflect availability in your buttons. You practise Jetpack Compose Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Jetpack Compose Academy?

No prior experience is required. Jetpack Compose Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 3 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Enabled, Disabled & Loading States” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Jetpack Compose Academy lesson?

Yes. Every Jetpack Compose Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Button and onClick
  2. Text, Outlined & Icon Buttons
  3. Enabled, Disabled & Loading States
  4. clickable on Any Composable
← Back to Jetpack Compose Academy