0Pricing
Jetpack Compose Academy · บทเรียน

TextField และ OutlinedTextField

อ่านสิ่งที่ผู้ใช้พิมพ์

TextField และ OutlinedTextField เป็นบทเรียน Jetpack Compose Academy ฟรีบน CoddyKit นี่คือบทเรียนที่ 1 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Jetpack Compose Academy และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Jetpack Compose Academy มีบทเรียนทั้งหมด 4 บทเรียน

บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ

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

คำถามที่พบบ่อย

บทเรียน “TextField และ OutlinedTextField” ฟรีหรือไม่

ใช่ — ข้อความเต็มของ “TextField และ OutlinedTextField” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Jetpack Compose Academy ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Jetpack Compose Academy มีบทเรียนทั้งหมด 4 บทเรียน

คุณจะเรียนรู้อะไรในบทเรียน “TextField และ OutlinedTextField”

อ่านสิ่งที่ผู้ใช้พิมพ์ คุณปฏิบัติ Jetpack Compose Academy ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน

คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Jetpack Compose Academy หรือไม่

ไม่จำเป็นต้องมีประสบการณ์มาก่อน Jetpack Compose Academy บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 1 จากทั้งหมด 4 บทเรียน

บทเรียน “TextField และ OutlinedTextField” ใช้เวลานานแค่ไหน

บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย

ฉันเขียนและรันโค้ดในบทเรียน Jetpack Compose Academy นี้ได้ไหม

ได้ บทเรียน Jetpack Compose Academy ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ

บทเรียนทั้งหมดในหลักสูตรนี้

  1. TextField และ OutlinedTextField
  2. ป้ายกำกับ ข้อความตัวอย่าง และไอคอนนำหน้า
  3. ชนิดแป้นพิมพ์และการดำเนินการ IME
  4. การตรวจสอบในบรรทัดและสถานะข้อผิดพลาด
← กลับไปที่ Jetpack Compose Academy