รูปภาพ ฟอนต์ และสตริงแบบ shared
ใช้ compose-resources ในทุกแพลตฟอร์ม
รูปภาพ ฟอนต์ และสตริงแบบ shared เป็นบทเรียน Kotlin Multiplatform Academy ฟรีบน CoddyKit นี่คือบทเรียนที่ 3 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Kotlin Multiplatform Academy และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Kotlin Multiplatform Academy มีบทเรียนทั้งหมด 4 บทเรียน
บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ
Assets Should Be Shared Too
Your logo, your fonts, your labels: why ship them twice? compose-resources lets every platform load the same assets. 🖼️
One Resources Folder
You drop assets into a shared composeResources directory. Images, fonts and strings all live in one place for every target.
Add the Resources Setup
Enabling resources generates a typed Res object. You reference assets through it instead of raw file paths.
commonMain.dependencies {
implementation(compose.components.resources)
}Folders by Asset Type
Resources are grouped into folders like drawable, font and values. The names tell the toolkit how to treat each file.
Show a Shared Image
Load a drawable with painterResource and the generated Res handle. The same picture renders on both apps.
Image(
painter = painterResource(Res.drawable.logo),
contentDescription = "Logo"
)Bundle a Custom Font
Place a font file in the font folder, then load it with Font and the Res handle to build a FontFamily.
val brand = FontFamily(Font(Res.font.inter_bold))Strings in One File
Define your text in a shared strings.xml. Each label gets a key, and the Res object exposes it to your UI.
<string name="welcome">Welcome back!</string>Read a Shared String
You fetch text with stringResource and the generated key. No more hardcoded labels scattered across screens.
Text(stringResource(Res.string.welcome))Type Safety for Free
Because Res is generated, a typo in an asset name fails to compile. You catch missing resources before users ever do. ✅
Strings Can Take Arguments
Add placeholders in a string and pass values at call time. The same stringResource call fills them in for you.
Text(stringResource(Res.string.greeting, userName))Assets Travel With Shared Code
Because resources live in the shared module, any app that uses your code gets the assets automatically. One source of truth. 🙂
Quick Check
Which function loads a shared drawable into a Compose Image?
Recap: Shared Look and Feel
You stored images, fonts and strings once and loaded them with the generated Res object. Every platform shares the same brand. 🎨
คำถามที่พบบ่อย
บทเรียน “รูปภาพ ฟอนต์ และสตริงแบบ shared” ฟรีหรือไม่
ใช่ — ข้อความเต็มของ “รูปภาพ ฟอนต์ และสตริงแบบ shared” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Kotlin Multiplatform Academy ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Kotlin Multiplatform Academy มีบทเรียนทั้งหมด 4 บทเรียน
คุณจะเรียนรู้อะไรในบทเรียน “รูปภาพ ฟอนต์ และสตริงแบบ shared”
ใช้ compose-resources ในทุกแพลตฟอร์ม คุณปฏิบัติ Kotlin Multiplatform Academy ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน
คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Kotlin Multiplatform Academy หรือไม่
ไม่จำเป็นต้องมีประสบการณ์มาก่อน Kotlin Multiplatform Academy บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 3 จากทั้งหมด 4 บทเรียน
บทเรียน “รูปภาพ ฟอนต์ และสตริงแบบ shared” ใช้เวลานานแค่ไหน
บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย
ฉันเขียนและรันโค้ดในบทเรียน Kotlin Multiplatform Academy นี้ได้ไหม
ได้ บทเรียน Kotlin Multiplatform Academy ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ
บทเรียนทั้งหมดในหลักสูตรนี้
- นำทางระหว่างหน้าจอ shared
- ส่งอาร์กิวเมนต์และลิงก์เชิงลึก
- รูปภาพ ฟอนต์ และสตริงแบบ shared
- แปลข้อความ UI แบบ shared