Kotlin tutorial

Lily's semantics, accessibility contracts and worldwide rules for Jetpack Compose on Android: every word is yours, every native control stays Material's, and a theme changes how a component looks, never what TalkBack reads.

What you'll build

A small contact form — a labelled field with a hint and an error, an error summary, a warning — first plain, then themed, in about 15 minutes.

Early and unreleased. The Kotlin libraries are not on Maven Central yet, so you build them from a copy of the monorepo. Their components are a first slice, not the whole catalog: see the list in step 2.

Before you start

You need a JDK 17 or later, an Android SDK with platform 37.2 (Compose 1.13 requires it and minSdk 24), Kotlin 2.4 and an app built with Jetpack Compose. The components use compose.foundation and compose.ui only: Lily never depends on Material.

Step 1 — Add the libraries

git clone https://github.com/LilyDesignSystem/lily-design-system

Until there is a release, the supported way to use the libraries is as modules of the repository's own Gradle build, lily-design-system-kotlin. Open it in Android Studio, add your app as a module (include(":my-app") in its settings.gradle.kts) and depend on the Lily modules by project, as the example app does:

// my-app/build.gradle.kts
dependencies {
    implementation(project(":lily-compose"))
    implementation(project(":lily-compose-themes"))
    // …your Compose BOM, foundation and activity-compose, as in lily-compose-examples-app
}

The modules are lily-core (Kotlin Multiplatform, no Android dependency: search folding, middle truncation, clinical formatting), lily-compose (the components), lily-compose-themes (generated tokens and LilyTheme) and lily-compose-examples (a worked example of every component). lily-compose-examples-app is a complete app to copy from.

Step 2 — Your first component

import androidx.compose.runtime.Composable
import io.github.lilydesignsystem.compose.WarningText

@Composable
fun Notice() {
    WarningText(prefix = "Warning", text = "You can be fined up to £5,000 if you do not register.")
}

WarningText keeps the prefix and the text together so TalkBack reads them as one sentence. The first slice has Field, ErrorSummary, SummaryList, WarningText, LilyAlert, LilyBadge, Tag, LilyCard, InsetText, Disclosure, the clinical views and the International Patient Summary. Lily ships no button, switch, checkbox, slider, date picker, sheet or navigation: on Compose those are Material 3's.

Step 3 — Compose a small form

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.text.BasicTextField
import androidx.compose.runtime.*
import io.github.lilydesignsystem.compose.*

@Composable
fun ContactForm() {
    var name by remember { mutableStateOf("") }
    var nameError by remember { mutableStateOf<String?>(null) }
    Column {
        nameError?.let { ErrorSummary(title = "There is a problem", problems = listOf(Problem(it) { /* focus the field */ })) }
        Field(label = "Full name", description = "As it appears on your passport", error = nameError,
              required = true, requiredLabel = "required") { fieldModifier ->
            BasicTextField(value = name, onValueChange = { name = it }, modifier = fieldModifier)
        }
        WarningText(prefix = "Warning", text = "You can be fined up to £5,000 if you do not register.")
    }
}

Field draws the visible label, the hint and the error, and hands its control a Modifier that carries the spoken name and the error: apply it to the control. ErrorSummary lists the problems and calls each one's lambda when it is activated, so you can move focus to the field.

Verified 2026-11-22: this form and the theme in step 5 were compiled against the modules with Gradle (compileDebugKotlin). The accessibility checks of the example app run on an emulator (see step 6).

Step 4 — The Compose idioms

  • Every word is yours. Lily has no default text and no string resources: labels, hints and errors are parameters, so the form speaks your app's language.
  • Pass the modifier to the control. Field gives its content a Modifier; a control that ignores it loses its spoken name.
  • Text follows the user. Text styles come from LocalLilyTextStyles, which defaults to the platform's text, so the user's font scale applies unchanged.
  • Spoken joins are line breaks, never words or punctuation of Lily's own, and tappable parts are at least 48 by 48 dp.

Step 5 — Theme it

Add lily-compose-themes and wrap the content once:

import androidx.compose.foundation.isSystemInDarkTheme
import io.github.lilydesignsystem.compose.themes.LilyTheme
import io.github.lilydesignsystem.compose.themes.LilyTokens

@Composable
fun Root() {
    LilyTheme(if (isSystemInDarkTheme()) LilyTokens.dark else LilyTokens.govUk) { ContactForm() }
}

The tokens are LilyTokens.light, dark, nhsEnglandPatients, govUk, uswds and japanDigitalAgency, generated from the same token files as the web themes. A theme decorates through LocalLilyDecoration, applied after each component's semantics, so it can change how a component looks but never what TalkBack reads. Text uses only the colour pairs the web themes gate at 4.5:1. Using a public-sector theme does not make your app that body's service: supply your own name and marks.

Step 6 — See it all working

lily-compose-examples has a worked example of every component and a searchable catalog you can host in your own activity; navigation stays yours:

setContent {
    var selected by rememberSaveable { mutableStateOf<String?>(null) }
    BackHandler(enabled = selected != null) { selected = null }
    ExampleCatalog(title = "Components", searchLabel = "Search components", selected = selected, onSelect = { selected = it })
}

Or install the ready-made example app on a device or emulator; its accessibility test runs Google's Accessibility Test Framework over the catalog and every detail view at font scale 1.0 and 2.0:

cd lily-design-system/lily-design-system-kotlin
./gradlew :lily-compose-examples-app:installDebug

Next steps

Questions along the way? The help page is full of answers — and if a step could be clearer, tell us and we'll gladly improve the tutorial.