共有Images、Fonts、Strings
すべてのプラットフォームでcompose-resourcesを使います
「共有Images、Fonts、Strings」はCoddyKit上の無料Kotlin Multiplatform Academyレッスンです。 これはレッスン3/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これは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. 🎨
よくある質問
「共有Images、Fonts、Strings」レッスンは無料ですか?
はい。「共有Images、Fonts、Strings」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Kotlin Multiplatform Academyコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Kotlin Multiplatform Academyコースには全4レッスンが含まれています。
「共有Images、Fonts、Strings」で何を学びますか?
すべてのプラットフォームでcompose-resourcesを使います ブラウザで直接実行するハンズオンコードでKotlin Multiplatform Academyを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。
Kotlin Multiplatform Academyを始めるのに経験は必要ですか?
事前経験は必要ありません。CoddyKitのKotlin Multiplatform Academyは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン3/4です。
「共有Images、Fonts、Strings」レッスンにはどのくらい時間がかかりますか?
ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。
このKotlin Multiplatform Academyレッスンでコードを書いて実行できますか?
はい。すべてのKotlin Multiplatform Academyレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。
このコースのすべてのレッスン
- 共有画面間を移動する
- ArgumentsとDeep Linksを渡す
- 共有Images、Fonts、Strings
- 共有UIテキストをローカライズする