0Pricing
Kotlin Multiplatform Academy · Lezione

Immagini, font e stringhe condivisi

Usare compose-resources su ogni piattaforma

Immagini, font e stringhe condivisi è una lezione Kotlin Multiplatform Academy gratuita su CoddyKit. Questa è la lezione 3 di 4. Puoi leggere la lezione completa qui gratuitamente — poi esercitati direttamente nel browser con un editor di codice integrato e un tutor IA disponibile 24/7. Fa parte del percorso di apprendimento Kotlin Multiplatform Academy, e i tuoi progressi si sincronizzano tra il web e l'app CoddyKit. Il corso Kotlin Multiplatform Academy include 4 lezioni in totale.

Parti di questa lezione non sono ancora state tradotte e vengono mostrate in inglese.

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

Domande Frequenti

La lezione «Immagini, font e stringhe condivisi» è gratuita?

Sì — il testo completo di «Immagini, font e stringhe condivisi» è gratuito qui sul web. Per esercitarvi in modo interattivo (un editor di codice integrato e un tutor IA 24/7) e sbloccare il resto del corso Kotlin Multiplatform Academy, passa a CoddyKit PRO. Il corso Kotlin Multiplatform Academy include 4 lezioni in totale.

Cosa imparerò in «Immagini, font e stringhe condivisi»?

Usare compose-resources su ogni piattaforma Eserciti Kotlin Multiplatform Academy con codice pratico che esegui direttamente nel browser, e un tutor IA 24/7 risponde alle tue domande mentre lavori sulla lezione.

Ho bisogno di esperienza per iniziare Kotlin Multiplatform Academy?

Non è richiesta alcuna esperienza precedente. Kotlin Multiplatform Academy su CoddyKit è strutturato per principianti e studenti avanzati, quindi puoi iniziare da qui o dall'inizio e procedere al tuo ritmo. Questa è la lezione 3 di 4.

Quanto tempo richiede la lezione «Immagini, font e stringhe condivisi»?

La maggior parte delle lezioni CoddyKit richiede circa 5–10 minuti. Ogni lezione è breve e interattiva, quindi fai progressi costanti e riprendi esattamente da dove hai lasciato su web e app.

Posso scrivere ed eseguire codice in questa lezione Kotlin Multiplatform Academy?

Sì. Ogni lezione Kotlin Multiplatform Academy include un editor di codice integrato, quindi scrivi ed esegui codice reale direttamente nel tuo browser e ricevi feedback istantaneo dall'IA — nessuna configurazione locale necessaria.

Tutte le lezioni di questo corso

  1. Navigare tra schermate condivise
  2. Passare argomenti e deep link
  3. Immagini, font e stringhe condivisi
  4. Localizzare il testo dell'interfaccia condivisa
← Torna a Kotlin Multiplatform Academy