0Pricing
Jetpack Compose Academy · Pelajaran

TextField & OutlinedTextField

Baca teks yang diketik pengguna.

TextField & OutlinedTextField adalah pelajaran Jetpack Compose Academy gratis di CoddyKit. Ini adalah pelajaran 1 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.

Why Text Fields Matter

Almost every app asks the user to type something. In Compose, the TextField is your gateway to reading that input. ✏️

The TextField Composable

A TextField shows an editable box. It needs a current value and a callback that fires every time the text changes.

TextField(
    value = name,
    onValueChange = { name = it }
)

State Drives the Value

The field never stores text itself. You hold it in state and feed it back in, so the UI always shows the latest value.

var name by remember { mutableStateOf("") }

onValueChange Closes the Loop

Each keystroke calls onValueChange with the new text. You save it to state, Compose redraws, and the field reflects what was typed.

onValueChange = { newText -> name = newText }

Meet OutlinedTextField

OutlinedTextField works exactly the same way, but draws a clean border around the input instead of a filled background.

OutlinedTextField(
    value = name,
    onValueChange = { name = it }
)

Filled vs Outlined

The filled TextField has a shaded box and underline. The outlined one is lighter and airier. They behave identically, so pick by style.

Add a Label

A label tells the user what the field is for. It floats above the text once the field is focused or filled.

OutlinedTextField(
    value = name,
    onValueChange = { name = it },
    label = { Text("Name") }
)

Single Line by Default

Set singleLine to true to keep input on one row. The keyboard then shows a Done action instead of a newline.

TextField(
    value = name,
    onValueChange = { name = it },
    singleLine = true
)

Read the Value Anywhere

Because the text lives in state, any other Composable can read it. Greet the user the moment they finish typing their name. 👋

Text("Hello, " + name)

It Is a Controlled Field

Compose fields are controlled: what you display is whatever you pass as value. Forget to update state and the field appears frozen.

Start Simple, Grow Later

A value plus an onValueChange is all you truly need. Labels, icons, and validation are extras you add on top.

Quick Check

Which parameter receives the user's new text on every keystroke?

Recap

You met TextField and OutlinedTextField: bind a value from state, update it in onValueChange, and add a label. That is text input in Compose. 🎉

Pertanyaan yang Sering Diajukan

Apakah pelajaran “TextField & OutlinedTextField” gratis?

Ya — teks lengkap “TextField & OutlinedTextField” 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 “TextField & OutlinedTextField”?

Baca teks yang diketik pengguna. 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 1 dari 4.

Berapa lama pelajaran “TextField & OutlinedTextField” 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. TextField & OutlinedTextField
  2. Label, Placeholder & Ikon Awalan
  3. Jenis Keyboard & Tindakan IME
  4. Validasi Sebaris & State Error
← Kembali ke Jetpack Compose Academy