0Pricing
Jetpack Compose Academy · Lesson

TopAppBar & Action Icons

Add a title bar with actions.

TopAppBar & Action Icons is a free Jetpack Compose 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 Jetpack Compose Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

The Title Bar

The strip across the top with your screen name and actions is the TopAppBar. It gives users a stable anchor that says where they are. 🧭

A Minimal TopAppBar

At its simplest, a TopAppBar just needs a title. Drop it into the Scaffold topBar slot and you have a real Material header.

TopAppBar(
    title = { Text("Inbox") }
)

Title Is a Composable

Notice the title takes a Composable lambda, not a String. That means you can put any content there, though usually a single Text fits best.

The navigationIcon Slot

The leading navigationIcon slot holds your back or menu button. Wrap an Icon in an IconButton so it is tappable and sized correctly.

navigationIcon = {
    IconButton(onClick = { }) {
        Icon(Icons.Default.Menu, "Menu")
    }
}

The actions Slot

Trailing buttons go in the actions slot. It is a RowScope, so each IconButton you add lines up neatly on the right edge.

actions = {
    IconButton(onClick = { }) {
        Icon(Icons.Default.Search, "Search")
    }
}

Always Pass contentDescription

Every Icon in a bar needs a contentDescription. Screen readers announce it, so a Search icon should say Search, not stay silent.

Bar Variants

Material 3 offers CenterAlignedTopAppBar, MediumTopAppBar, and LargeTopAppBar. They differ only in title size and alignment, so pick by feel.

Coloring the Bar

Use TopAppBarDefaults.topAppBarColors to recolor the container and title. Lean on theme colors so the bar stays consistent in light and dark.

colors = TopAppBarDefaults.topAppBarColors(
    containerColor = MaterialTheme.colorScheme.primary
)

Collapsing Bars

Pass a scrollBehavior and connect it to your content's nested scroll to make large bars shrink as the user scrolls down.

Do Not Overcrowd

Keep actions to two or three icons. Move the rest behind an overflow menu so the bar stays readable on small phones.

Wire It to Scaffold

The bar lives in Scaffold's topBar slot, so the content area shrinks automatically and your screen body never hides behind it.

Scaffold(topBar = { TopAppBar(title = { Text("Home") }) }) { p -> }

Quick Check

You add a search IconButton to a TopAppBar. Where does it belong?

Recap

A TopAppBar holds a title, a leading navigationIcon, and trailing actions. Describe every icon, keep it tidy, and place it in the topBar slot. ✨

Frequently asked questions

Is the “TopAppBar & Action Icons” lesson free?

Yes — the full text of “TopAppBar & Action Icons” 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 “TopAppBar & Action Icons”?

Add a title bar with actions. 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 2 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “TopAppBar & Action Icons” 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. Scaffold: The Screen Skeleton
  2. TopAppBar & Action Icons
  3. Bottom Bars & Floating Action Buttons
  4. Snackbars & SnackbarHostState
← Back to Jetpack Compose Academy