MaterialTheme และชุดสี
กำหนดชุดสีแอปไว้ในที่เดียว
MaterialTheme และชุดสี เป็นบทเรียน Jetpack Compose Academy ฟรีบน CoddyKit นี่คือบทเรียนที่ 1 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Jetpack Compose Academy และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Jetpack Compose Academy มีบทเรียนทั้งหมด 4 บทเรียน
บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ
One Theme to Rule Them
MaterialTheme is the wrapper that hands colors, fonts, and shapes to every Composable inside it, so you style your app in one place. 🎨
Wrap Your App
You usually wrap your whole UI in your app theme, which calls MaterialTheme at its core. Everything inside then reads from that single source.
AppTheme {
// your screens go here
}The colorScheme Slot
The first thing colorScheme defines is your palette: the named colors every Material component reaches for automatically.
MaterialTheme(
colorScheme = lightColorScheme()
) { /* app */ }Roles, Not Raw Colors
Material 3 uses color roles like primary and surface instead of raw hex everywhere, so components stay consistent and easy to retheme.
primary & onPrimary
The primary role is your brand color for key actions, and onPrimary is the readable color drawn on top of it, like white text on a blue button.
Surfaces & Backgrounds
The surface and background roles paint cards, sheets, and the screen behind everything, while onSurface keeps content legible on them.
Build a Light Scheme
You craft a palette with lightColorScheme, overriding only the roles you care about and letting sensible defaults fill the rest.
val scheme = lightColorScheme(
primary = Color(0xFF1A73E8)
)Read a Color in Code
Inside any Composable you grab theme colors through MaterialTheme.colorScheme, so a color change in the theme flows everywhere at once.
val c = MaterialTheme.colorScheme.primaryTint a Surface
Pass a role into a Composable and it stays on-theme; here a Surface paints itself with the primary color from the active colorScheme.
Surface(color = MaterialTheme.colorScheme.primary) {
Text("Hi")
}Container Roles
Roles like primaryContainer give softer, tonal backgrounds for chips and highlights, paired with onPrimaryContainer for their text.
Retheme in Seconds
Because components ask the theme for colors, swapping one colorScheme instantly restyles the entire app, with no per-widget edits. ✨
Quick Check
Where do your app-wide colors live in Material 3?
Recap: One Palette, Everywhere
You wrapped your app in MaterialTheme, defined a colorScheme of roles, and read colors back in code so one palette styles the whole UI. 🎉
คำถามที่พบบ่อย
บทเรียน “MaterialTheme และชุดสี” ฟรีหรือไม่
ใช่ — ข้อความเต็มของ “MaterialTheme และชุดสี” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Jetpack Compose Academy ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Jetpack Compose Academy มีบทเรียนทั้งหมด 4 บทเรียน
คุณจะเรียนรู้อะไรในบทเรียน “MaterialTheme และชุดสี”
กำหนดชุดสีแอปไว้ในที่เดียว คุณปฏิบัติ Jetpack Compose Academy ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน
คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Jetpack Compose Academy หรือไม่
ไม่จำเป็นต้องมีประสบการณ์มาก่อน Jetpack Compose Academy บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 1 จากทั้งหมด 4 บทเรียน
บทเรียน “MaterialTheme และชุดสี” ใช้เวลานานแค่ไหน
บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย
ฉันเขียนและรันโค้ดในบทเรียน Jetpack Compose Academy นี้ได้ไหม
ได้ บทเรียน Jetpack Compose Academy ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ
บทเรียนทั้งหมดในหลักสูตรนี้
- MaterialTheme และชุดสี
- ตัวกำหนดรูปแบบตัวอักษรและรูปทรง
- โหมดมืดและสีแบบไดนามิก
- สร้างระบบการออกแบบแบบกำหนดเอง