Composable Text
แสดงสตริงและควบคุมพื้นฐานของข้อความ
Composable Text เป็นบทเรียน Jetpack Compose Academy ฟรีบน CoddyKit นี่คือบทเรียนที่ 1 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Jetpack Compose Academy และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Jetpack Compose Academy มีบทเรียนทั้งหมด 4 บทเรียน
บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ
Meet Text
In Compose, you put words on screen with the Text composable. It is the simplest building block you will use in almost every screen.
Pass a String
Give Text a string and it renders instantly. No XML, no findViewById, just a function call describing what you want shown.
Text("Hello, Compose!")It Is Just a Function
Text is a composable function, not a class you inflate. You call it inside other composables, exactly like calling any Kotlin function. 🙂
Where Text Lives
You write Text inside a composable function such as your screen. Compose reads your code top to bottom and draws each element it finds.
@Composable
fun Greeting() {
Text("Welcome")
}Default Styling
With no extra arguments, Text uses sensible defaults from your theme: a readable size, the on-surface color, and the standard font.
Strings from Resources
For real apps, pull text from stringResource instead of hardcoding. This keeps your app translatable into every language you ship.
Text(stringResource(R.string.greeting))Combine with Variables
Because it is plain Kotlin, you can build the string from variables and templates before passing it to Text. Logic and UI live together.
val name = "Ada"
Text("Hi, " + name)Many Texts, One Screen
Need several lines? Just call Text multiple times. Each call is one independent element you can style on its own later.
maxLines Keeps It Tidy
Long content can be capped with maxLines so a label never grows taller than you expect. It simply stops drawing extra lines.
Text("A very long bio...", maxLines = 1)Reacts to State
When the string you pass changes, Text redraws automatically. You never call an update method; Compose tracks the value for you.
Your First Words
That is the whole idea: describe the text you want, and Compose paints it. Everything fancier is just extra arguments on this same call.
Quick Check
Which line correctly shows a greeting in Compose?
Recap
You met Text, the core composable for showing words. Pass it a string, lean on theme defaults, and it redraws whenever the value changes. 🎉
คำถามที่พบบ่อย
บทเรียน “Composable Text” ฟรีหรือไม่
ใช่ — ข้อความเต็มของ “Composable Text” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Jetpack Compose Academy ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Jetpack Compose Academy มีบทเรียนทั้งหมด 4 บทเรียน
คุณจะเรียนรู้อะไรในบทเรียน “Composable Text”
แสดงสตริงและควบคุมพื้นฐานของข้อความ คุณปฏิบัติ Jetpack Compose Academy ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน
คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Jetpack Compose Academy หรือไม่
ไม่จำเป็นต้องมีประสบการณ์มาก่อน Jetpack Compose Academy บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 1 จากทั้งหมด 4 บทเรียน
บทเรียน “Composable Text” ใช้เวลานานแค่ไหน
บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย
ฉันเขียนและรันโค้ดในบทเรียน Jetpack Compose Academy นี้ได้ไหม
ได้ บทเรียน Jetpack Compose Academy ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ
บทเรียนทั้งหมดในหลักสูตรนี้
- Composable Text
- ขนาด น้ำหนัก และรูปแบบตัวอักษร
- สี การจัดแนว และเนื้อหาล้น
- AnnotatedString: ข้อความผสมแบบมีรูปแบบ