0Pricing
Android Academy · Lesson

Buttons and Clicks

Add interactive buttons.

Buttons and Clicks is a free Android Academy lesson on CoddyKit — lesson 2 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 Android Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

What Is a Button?

A Button is a tappable composable. When the user taps it, your app runs some code.

Buttons need an onClick action and content to show, usually a Text label.

Button(onClick = { }) {
    Text("Tap me")
}

The onClick Lambda

The onClick parameter takes a lambda, which is code inside curly braces { }. That code runs each time the button is pressed.

You can put any logic there, like printing or changing data.

Button(onClick = {
    println("Clicked!")
}) {
    Text("Click")
}

Button Content

The content inside the trailing braces is a RowScope. You can place Text, Icons, or both.

Most buttons just hold a single Text label describing the action.

Button(onClick = { }) {
    Text("Save")
}

Counting Clicks with State

To react to taps, store a value with remember and mutableStateOf. When it changes, the UI updates.

Here each tap adds one to count.

var count by remember { mutableStateOf(0) }
Button(onClick = { count++ }) {
    Text("Count: $count")
}

Disabling a Button

The enabled parameter controls whether a button can be tapped. Set it to false to gray it out and block clicks.

This is useful while a form is incomplete.

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

OutlinedButton

OutlinedButton draws only a border with no fill. It works the same way but looks lighter.

Use it for secondary actions next to a stronger primary Button.

OutlinedButton(onClick = { }) {
    Text("Cancel")
}

TextButton

TextButton shows just a label with no border or fill. It is the lightest button style.

It fits well for low-emphasis actions like Skip or Learn more.

TextButton(onClick = { }) {
    Text("Skip")
}

Button Colors

You can recolor a Button with ButtonDefaults.buttonColors, passing a containerColor for the background.

Pick colors that match your brand and stay readable.

Button(
    onClick = { },
    colors = ButtonDefaults.buttonColors(
        containerColor = Color.Green
    )
) {
    Text("Go")
}

IconButton

IconButton is a small round tappable area meant for a single Icon, like a heart or menu.

It has no label, so it saves space in toolbars.

IconButton(onClick = { }) {
    Icon(Icons.Default.Favorite, contentDescription = "Like")
}

Shaping a Button

The shape parameter changes the corners. Use RoundedCornerShape with a dp value for rounder edges.

Bigger numbers give softer, pill-like buttons.

Button(
    onClick = { },
    shape = RoundedCornerShape(16.dp)
) {
    Text("Rounded")
}

Naming Click Functions

For tidy code, give onClick a named function instead of inline logic. This keeps the UI readable.

Pass the function reference or call it inside the lambda.

fun onSave() { println("Saved") }
Button(onClick = { onSave() }) {
    Text("Save")
}

Quick Check

Test your understanding of buttons.

Recap

You learned that Button uses onClick for its action and a content block for its label. State with remember lets clicks change the UI.

You also saw OutlinedButton, TextButton, IconButton, and how to set enabled, colors, and shape.

Next, you'll control spacing with padding.

Frequently asked questions

Is the “Buttons and Clicks” lesson free?

Yes — the full text of “Buttons and Clicks” is free to read here on the web, and the Android 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 Android Academy course, upgrade to CoddyKit PRO.

What will I learn in “Buttons and Clicks”?

Add interactive buttons. You practise Android 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 Android Academy?

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

How long does the “Buttons and Clicks” 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 Android Academy lesson?

Yes. Every Android 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. Styling Text
  2. Buttons and Clicks
  3. Spacing with Padding
  4. Colors and MaterialTheme
← Back to Android Academy