0Pricing
Jetpack Compose Academy · Pelajaran

TopAppBar & Ikon Tindakan

Tambahkan bilah judul dengan tindakan.

TopAppBar & Ikon Tindakan adalah pelajaran Jetpack Compose Academy gratis di CoddyKit. Ini adalah pelajaran 2 dari 4. Kamu bisa membaca pelajaran lengkapnya di bawah secara gratis — lalu praktikkan langsung di browser dengan editor kode bawaan dan tutor AI 24/7. Ini adalah bagian dari jalur belajar Jetpack Compose Academy, dan progresmu tersinkronisasi di web dan aplikasi CoddyKit. Kursus Jetpack Compose Academy mencakup 4 pelajaran total.

Bagian dari pelajaran ini belum diterjemahkan dan ditampilkan dalam bahasa Inggris.

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. ✨

Pertanyaan yang Sering Diajukan

Apakah pelajaran “TopAppBar & Ikon Tindakan” gratis?

Ya — teks lengkap “TopAppBar & Ikon Tindakan” gratis dibaca di sini di web. Untuk praktiknya secara interaktif (editor kode bawaan dan tutor AI 24/7) dan buka sisa kursus Jetpack Compose Academy, upgrade ke CoddyKit PRO. Kursus Jetpack Compose Academy mencakup 4 pelajaran total.

Apa yang akan aku pelajari di “TopAppBar & Ikon Tindakan”?

Tambahkan bilah judul dengan tindakan. Kamu berlatih Jetpack Compose Academy dengan kode praktik yang langsung kamu jalankan di browser, dan tutor AI 24/7 menjawab pertanyaanmu saat kamu mengerjakan pelajaran ini.

Apakah aku perlu pengalaman untuk memulai Jetpack Compose Academy?

Tidak diperlukan pengalaman sebelumnya. Jetpack Compose Academy di CoddyKit dirancang untuk pemula hingga pelajar tingkat lanjut, jadi kamu bisa memulai di sini atau dari awal dan belajar sesuai kecepatan kamu sendiri. Ini adalah pelajaran 2 dari 4.

Berapa lama pelajaran “TopAppBar & Ikon Tindakan” memakan waktu?

Sebagian besar pelajaran CoddyKit memakan waktu sekitar 5–10 menit. Setiap pelajaran ringkas dan interaktif, jadi kamu membuat kemajuan stabil dan melanjutkan dari tempat kamu tinggalkan di web dan aplikasi.

Bisakah aku menulis dan menjalankan kode dalam pelajaran Jetpack Compose Academy ini?

Ya. Setiap pelajaran Jetpack Compose Academy menyertakan editor kode bawaan, jadi kamu menulis dan menjalankan kode nyata langsung di browser dan mendapatkan umpan balik AI instan — tidak diperlukan penyiapan lokal.

Semua pelajaran dalam kursus ini

  1. Scaffold: Kerangka Layar
  2. TopAppBar & Ikon Tindakan
  3. Bilah Bawah & Floating Action Button
  4. Snackbar & SnackbarHostState
← Kembali ke Jetpack Compose Academy