Baris Statistik & Button Ikuti
Tambahkan detail interaktif ke kartu.
Baris Statistik & Button Ikuti adalah pelajaran Jetpack Compose Academy gratis di CoddyKit. Ini adalah pelajaran 3 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.
Add the Interactive Details
With the header done, you will add the lower half: a row of stats and a follow button that responds to taps. This is where the card comes alive. ⚡
One Stat Block
Each stat is two stacked Texts: a big number and a small label. A tiny Column holds them together as one neat block.
Column(horizontalAlignment = Alignment.CenterHorizontally) {
Text("128")
Text("Posts")
}Emphasize the Number
The count should pop while the label stays quiet. Give the number a bold style and the label a smaller one.
Text("128", style = MaterialTheme.typography.titleMedium)
Text("Posts", style = MaterialTheme.typography.labelSmall)Put Stats in a Row
Three stat blocks sit side by side, so wrap them in a Row. Each block becomes a child laid out left to right.
Row {
StatBlock("128", "Posts")
StatBlock("4.2k", "Followers")
StatBlock("180", "Following")
}Space the Stats Evenly
Spread the blocks across the card with Arrangement.SpaceEvenly on the Row, so the gaps are equal and balanced.
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.SpaceEvenly
) { /* ... */ }Add the Follow Button
Below the stats, add a Button. Its onClick lambda runs your code the moment the user taps it.
Button(onClick = { /* follow */ }) {
Text("Follow")
}Make It Full Width
A primary action button reads best across the whole card. Add fillMaxWidth so it spans edge to edge.
Button(
onClick = { /* follow */ },
modifier = Modifier.fillMaxWidth()
) { Text("Follow") }Track the Follow State
The button should toggle between Follow and Following. Hold that with remember and mutableStateOf so the UI reacts to taps.
var following by remember { mutableStateOf(false) }Flip State on Tap
Inside onClick, flip the boolean. Compose notices the state changed and redraws the button with new text automatically.
Button(onClick = { following = !following }) {
Text(if (following) "Following" else "Follow")
}Wire It Into the Card
Drop the stats Row and the Button below the header inside the outer Column. The full card now reads top to bottom in order.
An Interactive Card
You now have stats, a follow button, and live state. Tapping really changes the screen, which is the heart of a declarative Compose UI. 🎉
Quick Check
What lets the button text update when tapped?
Recap: Stats and Action
You built a Row of evenly spaced stat blocks and a full-width follow button driven by remembered state. Next you will refactor it all into clean, reusable pieces.
Pertanyaan yang Sering Diajukan
Apakah pelajaran “Baris Statistik & Button Ikuti” gratis?
Ya — teks lengkap “Baris Statistik & Button Ikuti” 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 “Baris Statistik & Button Ikuti”?
Tambahkan detail interaktif ke kartu. 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 3 dari 4.
Berapa lama pelajaran “Baris Statistik & Button Ikuti” 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
- Membuat Sketsa Layout Kartu Profil
- Bagian Avatar, Nama & Bio
- Baris Statistik & Button Ikuti
- Mengekstrak Composable yang Dapat Digunakan Kembali