Android Academy · Lesson

Buttons and Clicks

Add interactive buttons.

Lesson 2 of 413 steps

Buttons and Clicks is a free Android Academy lesson on CoddyKit. This is lesson 2 of 4. Any 3 lessons of this learning path are free to read in full — after that, CoddyKit PRO unlocks every lesson, plus hands-on practice with a built-in code editor and a 24/7 AI tutor. It is part of the Android Academy learning path, and your progress syncs across the web and the CoddyKit app. The Android Academy course includes 4 lessons in total.

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.

Free to start

Learn Kotlin with an AI tutor — free

Write and run real code in your browser, get instant help from a 24/7 AI tutor, and pick up where you left off on the web or in the app.

Courses
36
Lessons
152

Frequently Asked Questions

Is the “Buttons and Clicks” lesson free?

Yes — any 3 lessons of the Android Academy learning path, including “Buttons and Clicks”, are free to read in full here on the web. After that, CoddyKit PRO unlocks every lesson, plus interactive practice with a built-in code editor and a 24/7 AI tutor. The Android Academy course includes 4 lessons in total.

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, so you can start here or from the beginning and move at your own pace. This is lesson 2 of 4.

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