Mehdi TmimiMobile DevelopmentMobile

Mobile Development Lab 2 Part 3 · parts 0–7

Make it beautiful: the theme and the Modifier

Your Add button is not orange. Who chose its colour?

Goal Give your screen Lab 1’s look: its colours in one theme, each shape painted by a Modifier chain.

The idea

The theme hands its colours down; the Modifier paints link by link

kotlin+java › com.yourname.notes.ui.theme › Theme.ktRead only
package com.yourname.notes.ui.theme
import android.app.Activityimport android.os.Buildimport androidx.compose.foundation.isSystemInDarkThemeimport androidx.compose.material3.MaterialThemeimport androidx.compose.material3.darkColorSchemeimport androidx.compose.material3.dynamicDarkColorSchemeimport androidx.compose.material3.dynamicLightColorSchemeimport androidx.compose.material3.lightColorSchemeimport androidx.compose.runtime.Composableimport androidx.compose.ui.platform.LocalContext
private val DarkColorScheme = darkColorScheme( primary = Purple80, secondary = PurpleGrey80, tertiary = Pink80)
private val LightColorScheme = lightColorScheme( primary = Purple40, secondary = PurpleGrey40, tertiary = Pink40
/* Other default colors to override background = Color(0xFFFFFBFE), surface = Color(0xFFFFFBFE), onPrimary = Color.White, onSecondary = Color.White, onTertiary = Color.White, onBackground = Color(0xFF1C1B1F), onSurface = Color(0xFF1C1B1F), */)
@Composablefun NotesTheme( darkTheme: Boolean = isSystemInDarkTheme(), // Dynamic color is available on Android 12+ dynamicColor: Boolean = true, content: @Composable () -> Unit) { val colorScheme = when { dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> { val context = LocalContext.current if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context) }
darkTheme -> DarkColorScheme else -> LightColorScheme }
MaterialTheme( colorScheme = colorScheme, typography = Typography, content = content )}

The template’s Theme.kt, as the wizard wrote it. Step 3.1 replaces it.

  1. dynamicColor: Boolean = true: the template turns dynamic colour on.
  2. On Android 12 and later, dynamicLightColorScheme builds the colours from your wallpaper. That is your Add’s colour.
  3. MaterialTheme hands those colours to everything inside it: Scaffold, your screen, the button.
NotesTheme { … }hands down its colours
Scaffold { … }
NotesScreen()
Button(…) paints itself with primary
  • The template: primary comes from your wallpaper.
  • Your theme, step 3.1: primary = Brand, Lab 1’s orange.

Each call sits inside the one above it. A composable takes its colours from the theme, unless its code names one.

kotlin+java › com.yourname.notes › NotesScreen.ktRead only
package com.yourname.notes
import androidx.compose.foundation.Imageimport androidx.compose.foundation.backgroundimport androidx.compose.foundation.borderimport androidx.compose.foundation.layout.Boximport androidx.compose.foundation.layout.Columnimport androidx.compose.foundation.layout.Rowimport androidx.compose.foundation.layout.fillMaxSizeimport androidx.compose.foundation.layout.fillMaxWidthimport androidx.compose.foundation.layout.heightimport androidx.compose.foundation.layout.paddingimport androidx.compose.foundation.layout.sizeimport androidx.compose.foundation.layout.widthimport androidx.compose.foundation.shape.RoundedCornerShapeimport androidx.compose.foundation.text.BasicTextFieldimport androidx.compose.foundation.text.KeyboardOptionsimport androidx.compose.material3.Buttonimport androidx.compose.material3.MaterialThemeimport androidx.compose.material3.Textimport androidx.compose.material3.TextButtonimport androidx.compose.runtime.Composableimport androidx.compose.ui.Alignmentimport androidx.compose.ui.Modifierimport androidx.compose.ui.draw.clipimport androidx.compose.ui.draw.shadowimport androidx.compose.ui.graphics.Brushimport androidx.compose.ui.graphics.SolidColorimport androidx.compose.ui.res.painterResourceimport androidx.compose.ui.text.font.FontWeightimport androidx.compose.ui.text.input.ImeActionimport androidx.compose.ui.text.input.KeyboardCapitalizationimport androidx.compose.ui.text.style.TextAlignimport androidx.compose.ui.tooling.preview.Previewimport androidx.compose.ui.unit.dpimport androidx.compose.ui.unit.emimport androidx.compose.ui.unit.spimport com.yourname.notes.ui.theme.Brandimport com.yourname.notes.ui.theme.CardWhiteimport com.yourname.notes.ui.theme.Fieldimport com.yourname.notes.ui.theme.HeaderEndimport com.yourname.notes.ui.theme.Inkimport com.yourname.notes.ui.theme.Lineimport com.yourname.notes.ui.theme.Mutedimport com.yourname.notes.ui.theme.NotesThemeimport com.yourname.notes.ui.theme.OnBrand
@Composablefun NotesScreen(modifier: Modifier = Modifier) { Column(modifier = modifier.fillMaxSize()) { Box { // The header: a gradient with round corners Column( modifier = Modifier .padding(16.dp) .fillMaxWidth() .height(168.dp) .clip(RoundedCornerShape(28.dp)) .background(Brush.linearGradient(listOf(Brand, HeaderEnd))) .padding(start = 16.dp, top = 20.dp) ) { Image( painter = painterResource(R.drawable.ic_notes), contentDescription = "Notes logo", modifier = Modifier.size(36.dp) ) Row(modifier = Modifier.padding(top = 4.dp)) { Text( text = "Notes", color = OnBrand, fontSize = 30.sp, fontWeight = FontWeight.Black, modifier = Modifier.alignByBaseline() ) Text( text = "0", color = Brand, fontSize = 14.sp, fontWeight = FontWeight.Bold, modifier = Modifier .padding(start = 8.dp) .alignByBaseline() .background(CardWhite, RoundedCornerShape(12.dp)) .padding(horizontal = 10.dp, vertical = 2.dp) ) } }
// The composer: a white card that overlaps the header Column( modifier = Modifier .padding(start = 32.dp, top = 136.dp, end = 32.dp) .fillMaxWidth() .shadow(6.dp, RoundedCornerShape(20.dp)) .background(CardWhite) .padding(16.dp) ) { NotesField( value = "", onValueChange = { }, hint = "Title", singleLine = true ) NotesField( value = "", onValueChange = { }, hint = "Write something…", minLines = 3, modifier = Modifier.padding(top = 8.dp) ) Row( modifier = Modifier.padding(top = 8.dp), verticalAlignment = Alignment.CenterVertically ) { Text( text = "0 / 140", color = Muted, fontSize = 12.sp, modifier = Modifier.weight(1f) ) TextButton( onClick = { }, modifier = Modifier.width(88.dp) ) { Text("Clear") } Button( onClick = { }, shape = RoundedCornerShape(12.dp), modifier = Modifier .padding(start = 4.dp) .width(88.dp) ) { Text("Add") } } } }
// The list's title, and its hint on the right Row(modifier = Modifier.padding(start = 32.dp, top = 24.dp, end = 32.dp)) { Text( text = "YOUR NOTES", color = Muted, fontSize = 12.sp, fontWeight = FontWeight.Bold, letterSpacing = 0.1.em, modifier = Modifier.alignByBaseline() ) Text( text = "Tap to open · hold to delete", color = Muted, fontSize = 12.sp, textAlign = TextAlign.End, modifier = Modifier .padding(start = 16.dp) .weight(1f) .alignByBaseline() ) } }}
// Lab 1's style NotesField, as a function: the same look for both text fields@Composablefun NotesField( value: String, onValueChange: (String) -> Unit, hint: String, modifier: Modifier = Modifier, singleLine: Boolean = false, minLines: Int = 1) { BasicTextField( value = value, onValueChange = onValueChange, modifier = modifier .fillMaxWidth() .background(Field, RoundedCornerShape(12.dp)) .border(1.dp, Line, RoundedCornerShape(12.dp)) .padding(horizontal = 14.dp, vertical = 12.dp), textStyle = MaterialTheme.typography.bodyLarge.copy(color = Ink), singleLine = singleLine, minLines = minLines, keyboardOptions = KeyboardOptions( capitalization = KeyboardCapitalization.Sentences, imeAction = if (singleLine) ImeAction.Next else ImeAction.Default ), cursorBrush = SolidColor(Brand), decorationBox = { innerTextField -> Box { if (value.isEmpty()) { Text(text = hint, color = Muted) } innerTextField() } } )}
@Preview(showBackground = true)@Composablefun NotesScreenPreview() { NotesTheme { NotesScreen() }}

The header at the end of this part. You type lines 58 and 59 in step 3.3.

  1. padding(16.dp) before any paint: space around the box, a margin.
  2. fillMaxWidth() and height(168.dp): the box’s size.
  3. clip(RoundedCornerShape(28.dp)): the corners are cut; what follows paints only inside.
  4. background(…): the paint, orange to rose, from the top-left corner.
  5. padding(start = 16.dp, top = 20.dp) after the paint: space inside, a padding.
  1. a margin
  2. the size
  3. the corners
  4. the paint
  5. a padding

The header, link by link: each call works on what the calls above it made. Swap two links and the result changes.

Read a chain top to bottom: a padding before background is a margin, after it a padding (sheet card 9). No shape drawables: every shape is a chain.

Lab 1 beside it colors.xml, themes.xml, a shape drawable
  • colors.xml → Color.kt: the same colours, as Kotlin values (brand → Brand).
  • themes.xml → NotesTheme: colorPrimary becomes primary = Brand.
  • The shape drawables → Modifier links: bg_header.xml becomes clip + background.

Lab 1 · themes.xml

res › values › themes.xmlRead only
<resources>    <style name="Theme.Notes" parent="Theme.Material3.Light.NoActionBar">        <item name="android:windowLightStatusBar">true</item>        <item name="android:windowBackground">@color/paper</item>        <item name="colorPrimary">@color/brand</item>        <item name="colorOnPrimary">@color/on_brand</item>        <item name="colorControlActivated">@color/brand</item>        <item name="colorOutline">@color/muted</item>    </style>
<style name="NotesField"> <item name="android:background">@drawable/bg_field</item> <item name="android:paddingStart">14dp</item> <item name="android:paddingEnd">14dp</item> <item name="android:paddingTop">12dp</item> <item name="android:paddingBottom">12dp</item> <item name="android:textColor">@color/ink</item> <item name="android:textColorHint">@color/muted</item> <item name="android:textSize">16sp</item> </style></resources>

Lab 1 · bg_header.xml

res › drawable › bg_header.xmlRead only
<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android"    android:shape="rectangle">    <gradient        android:angle="315"        android:endColor="@color/header_end"        android:startColor="@color/brand" />    <corners android:radius="28dp" /></shape>
Part 2 not finished, or a fresh project? Start here about 4 min
  1. The project: your own from Part 2, or a fresh one: Part 0, steps 0.2 to 0.4 (about 10 minutes).

  2. Your package name, for the code of this page:

    Without JavaScript, the code says com.yourname.notes: replace yourname by the name you chose.

  3. MainActivity.kt (the tree shows it as MainActivity, with a class icon): open it, in kotlin+java › com.yourname.notes, select all, then paste this file.

    kotlin+java › com.yourname.notes › MainActivity.ktReplace the whole file
    package com.yourname.notes
    import android.os.Bundleimport androidx.activity.ComponentActivityimport androidx.activity.compose.setContentimport androidx.activity.enableEdgeToEdgeimport androidx.compose.foundation.layout.WindowInsetsimport androidx.compose.foundation.layout.fillMaxSizeimport androidx.compose.foundation.layout.paddingimport androidx.compose.foundation.layout.safeDrawingimport androidx.compose.material3.Scaffoldimport androidx.compose.ui.Modifierimport com.yourname.notes.ui.theme.NotesTheme
    class MainActivity : ComponentActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) enableEdgeToEdge() setContent { NotesTheme { Scaffold( modifier = Modifier.fillMaxSize(), // keep the screen out of the status bar, the gesture bar and the keyboard contentWindowInsets = WindowInsets.safeDrawing ) { innerPadding -> NotesScreen(modifier = Modifier.padding(innerPadding)) } } } }}
  4. NotesScreen.kt: open it, select all, then paste this file. Missing? Right-click kotlin+java › com.yourname.notes, the one without (test), then NewKotlin Class/File: type NotesScreen, click File in the list, then press Enter.

    kotlin+java › com.yourname.notes › NotesScreen.ktReplace the whole file
    package com.yourname.notes
    import androidx.compose.foundation.Imageimport androidx.compose.foundation.backgroundimport androidx.compose.foundation.borderimport androidx.compose.foundation.layout.Boximport androidx.compose.foundation.layout.Columnimport androidx.compose.foundation.layout.Rowimport androidx.compose.foundation.layout.fillMaxSizeimport androidx.compose.foundation.layout.fillMaxWidthimport androidx.compose.foundation.layout.heightimport androidx.compose.foundation.layout.paddingimport androidx.compose.foundation.layout.sizeimport androidx.compose.foundation.layout.widthimport androidx.compose.foundation.text.BasicTextFieldimport androidx.compose.material3.Buttonimport androidx.compose.material3.Textimport androidx.compose.material3.TextButtonimport androidx.compose.runtime.Composableimport androidx.compose.ui.Alignmentimport androidx.compose.ui.Modifierimport androidx.compose.ui.graphics.Colorimport androidx.compose.ui.res.painterResourceimport androidx.compose.ui.text.style.TextAlignimport androidx.compose.ui.tooling.preview.Previewimport androidx.compose.ui.unit.dpimport androidx.compose.ui.unit.spimport com.yourname.notes.ui.theme.NotesTheme
    @Composablefun NotesScreen(modifier: Modifier = Modifier) { Column(modifier = modifier.fillMaxSize()) { Box { // The header Column( modifier = Modifier .padding(16.dp) .fillMaxWidth() .height(168.dp) .background(Color(0xFFC2410C)) .padding(start = 16.dp, top = 20.dp) ) { Image( painter = painterResource(R.drawable.ic_launcher_foreground), contentDescription = "Notes logo", modifier = Modifier.size(36.dp) ) Row(modifier = Modifier.padding(top = 4.dp)) { Text( text = "Notes", color = Color.White, fontSize = 30.sp, modifier = Modifier.alignByBaseline() ) Text( text = "0", color = Color.White, modifier = Modifier .padding(start = 8.dp) .alignByBaseline() ) } }
    // The composer: a white card that overlaps the header Column( modifier = Modifier .padding(start = 32.dp, top = 136.dp, end = 32.dp) .fillMaxWidth() .background(Color.White) .padding(16.dp) ) { BasicTextField( value = "", onValueChange = { }, modifier = Modifier.fillMaxWidth().border(1.dp, Color.LightGray).padding(12.dp) ) BasicTextField( value = "", onValueChange = { }, modifier = Modifier.padding(top = 8.dp).fillMaxWidth().border(1.dp, Color.LightGray).padding(12.dp) ) Row( modifier = Modifier.padding(top = 8.dp), verticalAlignment = Alignment.CenterVertically ) { Text(text = "0 / 140", modifier = Modifier.weight(1f)) TextButton(onClick = { }, modifier = Modifier.width(88.dp)) { Text("Clear") } Button( onClick = { }, modifier = Modifier .padding(start = 4.dp) .width(88.dp) ) { Text("Add") } } } }
    // The list's title, and its hint on the right Row(modifier = Modifier.padding(start = 32.dp, top = 24.dp, end = 32.dp)) { Text(text = "YOUR NOTES", modifier = Modifier.alignByBaseline()) Text( text = "Tap to open · hold to delete", textAlign = TextAlign.End, modifier = Modifier .padding(start = 16.dp) .weight(1f) .alignByBaseline() ) } }}
    @Preview(showBackground = true)@Composablefun NotesScreenPreview() { NotesTheme { NotesScreen() }}
  5. Restarting this part? Also delete res › drawable › ic_notes.xml (right-click it, Delete…, OK). Keep colors.xml as it is: in step 3.1, skip action d if the paper line is already there. Until 3.1, Add may already be orange, on paper: that is fine.

  6. ▶. You are ready when the phone shows the skeleton: an orange band, a white card with two grey boxes, Add in your wallpaper’s colour.

The phone at the end of Part 2: a flat orange band with the launcher’s robot and Notes 0, a white card with two grey-bordered boxes, 0 / 140, Clear and a blue-grey Add, then YOUR NOTES and its hint.
Where you start
The phone at the end of this part: the orange to rose header with round corners, the white notes logo and the pill 0, the floating card with Title, Write something…, 0 / 140, Clear and an orange Add, on paper.
Where you arrive
  1. 3.1 the colours and the theme
  2. 3.2 the fields, the card, the text
  3. 3.3 the gradient and the logo

Before you start

By the end you can

  • say where a composable gets its colours: from the theme, unless its code names one;
  • move a palette into Color.kt and a light theme;
  • paint a box link by link: corners, a gradient, a border, a shadow.
  • Kotlin kotlin+java › com.yourname.notes
  • Resources res › values · res › drawable
  • Emulator

Step 1 of 3

Give the app Lab 1’s colours in a light theme

8 min

Goal Replace the template’s colours with Lab 1’s palette and a theme without dynamic colour.

  • Kotlin kotlin+java › com.yourname.notes › ui.theme
  • Resources res › values › colors.xml · themes.xml
  • Emulator
  1. Paste Lab 1’s colours, as Kotlin values.

    1. In the Project window, open kotlin+java › com.yourname.notes › ui.theme, then double-click Color.kt.
    2. Click Copy the file on the panel below.
    3. In Color.kt, click in the text, press Ctrl+A, then Ctrl+V. Theme.kt turns red: b fixes it.
    Project › Android Tool window · leftFull size
    The Project window, Android view: kotlin+java › com.yourname.notes open on the ui.theme package (Color.kt, selected, Theme.kt and Type.kt), MainActivity and NotesScreen.kt; below, res › values with colors.xml, strings.xml and themes.xml.
    1. ui.theme › Color.kt: double-click it.
    kotlin+java › com.yourname.notes.ui.theme › Color.ktReplace the whole file
    package com.yourname.notes.ui.theme
    import androidx.compose.ui.graphics.Color
    // Lab 1's colors.xml, in Kotlin: the same names, the same hex valuesval Brand = Color(0xFFC2410C)val OnBrand = Color(0xFFFFFFFF)val HeaderEnd = Color(0xFFE11D48)val Paper = Color(0xFFFFF8F1)val CardWhite = Color(0xFFFFFFFF)val Field = Color(0xFFFBF6F0)val Line = Color(0xFFE7D9CB)val Ink = Color(0xFF1F1A17)val Muted = Color(0xFF6B6159)val ErrorRed = Color(0xFFB91C1C)
    val NoteButter = Color(0xFFFFF1C9)val NoteButterLine = Color(0xFFF2D27A)val NoteMint = Color(0xFFD9F5E6)val NoteMintLine = Color(0xFF93D9B4)val NoteLavender = Color(0xFFECE6FF)val NoteLavenderLine = Color(0xFFC6B8FA)val NotePeach = Color(0xFFFFE1D6)val NotePeachLine = Color(0xFFF7B29A)

    Color(0xFFC2410C): FF (opaque), then Lab 1’s C2410C.

  2. Paste The theme: light only, no dynamic colour.

    1. Double-click Theme.kt, in the same ui.theme folder.
    2. Click Copy the file on the panel below.
    3. In Theme.kt, click in the text, press Ctrl+A, then Ctrl+V.
    kotlin+java › com.yourname.notes.ui.theme › Theme.ktReplace the whole file
    package com.yourname.notes.ui.theme
    import androidx.compose.material3.MaterialThemeimport androidx.compose.material3.lightColorSchemeimport androidx.compose.runtime.Composable
    // Lab 1's themes.xml, in Kotlin: light only, and no dynamic colourprivate val NotesColors = lightColorScheme( primary = Brand, onPrimary = OnBrand, background = Paper, surface = Paper, onSurface = Ink, outline = Muted, error = ErrorRed)
    @Composablefun NotesTheme(content: @Composable () -> Unit) { MaterialTheme( colorScheme = NotesColors, typography = Typography, content = content )}

    primary = Brand: the colour of every Button. content: @Composable () -> Unit: the screen you write between the braces of NotesTheme { } (sheet card 7).

  3. Paste The text style, spaced as in Lab 1.

    1. Double-click Type.kt, in the same folder.
    2. Click Copy the file on the panel below.
    3. In Type.kt, click in the text, press Ctrl+A, then Ctrl+V.
    kotlin+java › com.yourname.notes.ui.theme › Type.ktReplace the whole file
    package com.yourname.notes.ui.theme
    import androidx.compose.material3.Typographyimport androidx.compose.ui.text.PlatformTextStyleimport androidx.compose.ui.text.TextStyleimport androidx.compose.ui.text.font.FontFamilyimport androidx.compose.ui.text.font.FontWeightimport androidx.compose.ui.unit.sp
    // Set of Material typography styles to start withval Typography = Typography( bodyLarge = TextStyle( fontFamily = FontFamily.Default, fontWeight = FontWeight.Normal, fontSize = 16.sp, // Only to match Lab 1's TextView spacing (a little space above and below the letters). // Compose's default is false: this is not a styling technique, just pixel parity with Lab 1. platformStyle = PlatformTextStyle(includeFontPadding = true) ) /* Other default text styles to override titleLarge = TextStyle( fontFamily = FontFamily.Default, fontWeight = FontWeight.Normal, fontSize = 22.sp, lineHeight = 28.sp, letterSpacing = 0.sp ), labelSmall = TextStyle( fontFamily = FontFamily.Default, fontWeight = FontWeight.Medium, fontSize = 11.sp, lineHeight = 16.sp, letterSpacing = 0.5.sp ) */)
  4. Paste The paper colour, in colors.xml.

    1. Open res › values › colors.xml, then click Copy 1 line on its panel.
    2. Click at the end of line 9, press Enter, then Ctrl+V.
    res › values › colors.xmlAdd the marked lines
    <?xml version="1.0" encoding="utf-8"?><resources>    <color name="purple_200">#FFBB86FC</color>    <color name="purple_500">#FF6200EE</color>    <color name="purple_700">#FF3700B3</color>    <color name="teal_200">#FF03DAC5</color>    <color name="teal_700">#FF018786</color>    <color name="black">#FF000000</color>    <color name="white">#FFFFFFFF</color>    <color name="paper">#FFF8F1</color></resources>
  5. Paste The window behind Compose, painted paper.

    1. Open res › values › themes.xml, then click Copy the file on its panel.
    2. In themes.xml, click in the text, press Ctrl+A, then Ctrl+V.
    res › values › themes.xmlReplace the whole file
    <?xml version="1.0" encoding="utf-8"?><resources>
    <style name="Theme.Notes" parent="android:Theme.Material.Light.NoActionBar"> <!-- The window behind Compose, seen while the app starts: paper, as in Lab 1 --> <item name="android:windowBackground">@color/paper</item> </style></resources>

    The window behind Compose is still XML: you see it while the app starts.

  6. The theme, on the phone.

    1. Click ▶ Run 'app' and watch the start: paper from the first frame.
    2. Look at Add: orange. The header has not changed: its code names its own colour.
The phone after step 3.1: Part 2’s skeleton on a paper background, the flat orange band with the robot, two grey-bordered boxes, and an orange Add.

You should see Add in orange, on paper. The fields and the header wait for 3.2 and 3.3.

Done I see Add in orange, on paper.

Stuck? 3 symptoms · the files
  • Unresolved reference 'Brand'., in Theme.kt Color.kt still holds the template’s colours. Paste it again (action a).
  • error: resource color/paper (aka com.yourname.notes:color/paper) not found. colors.xml has no paper line. Add it (action d).
  • Add is still in your wallpaper’s colour Theme.kt still has dynamicColor. Paste it again (action b), then ▶.

The Kotlin files and themes.xml are the panels above: Copy the file on each. colors.xml at the end of this step:

res › values › colors.xmlReplace the whole file
<?xml version="1.0" encoding="utf-8"?><resources>    <color name="purple_200">#FFBB86FC</color>    <color name="purple_500">#FF6200EE</color>    <color name="purple_700">#FF3700B3</color>    <color name="teal_200">#FF03DAC5</color>    <color name="teal_700">#FF018786</color>    <color name="black">#FF000000</color>    <color name="white">#FFFFFFFF</color>    <color name="paper">#FFF8F1</color></resources>

Step 2 of 3

Dress the fields, the card and the text

10 min

Goal Paste the dressed screen: Lab 1’s field style as a function, the card’s shadow, the text sizes, the pill.

  • Kotlin NotesScreen.kt · Split
  • Emulator
  1. Paste The dressed screen: the whole NotesScreen.kt.

    1. Click the NotesScreen.kt tab, or double-click it in kotlin+java › com.yourname.notes.
    2. Click Copy the file on the panel below.
    3. In NotesScreen.kt, click in the code, press Ctrl+A, then Ctrl+V.
    4. Three imports stay grey, unused: clip, Brush, HeaderEnd. Step 3.3 uses them.
    kotlin+java › com.yourname.notes › NotesScreen.ktReplace the whole file
    package com.yourname.notes
    import androidx.compose.foundation.Imageimport androidx.compose.foundation.backgroundimport androidx.compose.foundation.borderimport androidx.compose.foundation.layout.Boximport androidx.compose.foundation.layout.Columnimport androidx.compose.foundation.layout.Rowimport androidx.compose.foundation.layout.fillMaxSizeimport androidx.compose.foundation.layout.fillMaxWidthimport androidx.compose.foundation.layout.heightimport androidx.compose.foundation.layout.paddingimport androidx.compose.foundation.layout.sizeimport androidx.compose.foundation.layout.widthimport androidx.compose.foundation.shape.RoundedCornerShapeimport androidx.compose.foundation.text.BasicTextFieldimport androidx.compose.foundation.text.KeyboardOptionsimport androidx.compose.material3.Buttonimport androidx.compose.material3.MaterialThemeimport androidx.compose.material3.Textimport androidx.compose.material3.TextButtonimport androidx.compose.runtime.Composableimport androidx.compose.ui.Alignmentimport androidx.compose.ui.Modifierimport androidx.compose.ui.draw.clipimport androidx.compose.ui.draw.shadowimport androidx.compose.ui.graphics.Brushimport androidx.compose.ui.graphics.SolidColorimport androidx.compose.ui.res.painterResourceimport androidx.compose.ui.text.font.FontWeightimport androidx.compose.ui.text.input.ImeActionimport androidx.compose.ui.text.input.KeyboardCapitalizationimport androidx.compose.ui.text.style.TextAlignimport androidx.compose.ui.tooling.preview.Previewimport androidx.compose.ui.unit.dpimport androidx.compose.ui.unit.emimport androidx.compose.ui.unit.spimport com.yourname.notes.ui.theme.Brandimport com.yourname.notes.ui.theme.CardWhiteimport com.yourname.notes.ui.theme.Fieldimport com.yourname.notes.ui.theme.HeaderEndimport com.yourname.notes.ui.theme.Inkimport com.yourname.notes.ui.theme.Lineimport com.yourname.notes.ui.theme.Mutedimport com.yourname.notes.ui.theme.NotesThemeimport com.yourname.notes.ui.theme.OnBrand
    @Composablefun NotesScreen(modifier: Modifier = Modifier) { Column(modifier = modifier.fillMaxSize()) { Box { // The header Column( modifier = Modifier .padding(16.dp) .fillMaxWidth() .height(168.dp) .background(Brand) .padding(start = 16.dp, top = 20.dp) ) { Image( painter = painterResource(R.drawable.ic_launcher_foreground), contentDescription = "Notes logo", modifier = Modifier.size(36.dp) ) Row(modifier = Modifier.padding(top = 4.dp)) { Text( text = "Notes", color = OnBrand, fontSize = 30.sp, fontWeight = FontWeight.Black, modifier = Modifier.alignByBaseline() ) Text( text = "0", color = Brand, fontSize = 14.sp, fontWeight = FontWeight.Bold, modifier = Modifier .padding(start = 8.dp) .alignByBaseline() .background(CardWhite, RoundedCornerShape(12.dp)) .padding(horizontal = 10.dp, vertical = 2.dp) ) } }
    // The composer: a white card that overlaps the header Column( modifier = Modifier .padding(start = 32.dp, top = 136.dp, end = 32.dp) .fillMaxWidth() .shadow(6.dp, RoundedCornerShape(20.dp)) .background(CardWhite) .padding(16.dp) ) { NotesField( value = "", onValueChange = { }, hint = "Title", singleLine = true ) NotesField( value = "", onValueChange = { }, hint = "Write something…", minLines = 3, modifier = Modifier.padding(top = 8.dp) ) Row( modifier = Modifier.padding(top = 8.dp), verticalAlignment = Alignment.CenterVertically ) { Text( text = "0 / 140", color = Muted, fontSize = 12.sp, modifier = Modifier.weight(1f) ) TextButton( onClick = { }, modifier = Modifier.width(88.dp) ) { Text("Clear") } Button( onClick = { }, shape = RoundedCornerShape(12.dp), modifier = Modifier .padding(start = 4.dp) .width(88.dp) ) { Text("Add") } } } }
    // The list's title, and its hint on the right Row(modifier = Modifier.padding(start = 32.dp, top = 24.dp, end = 32.dp)) { Text( text = "YOUR NOTES", color = Muted, fontSize = 12.sp, fontWeight = FontWeight.Bold, letterSpacing = 0.1.em, modifier = Modifier.alignByBaseline() ) Text( text = "Tap to open · hold to delete", color = Muted, fontSize = 12.sp, textAlign = TextAlign.End, modifier = Modifier .padding(start = 16.dp) .weight(1f) .alignByBaseline() ) } }}
    // Lab 1's style NotesField, as a function: the same look for both text fields@Composablefun NotesField( value: String, onValueChange: (String) -> Unit, hint: String, modifier: Modifier = Modifier, singleLine: Boolean = false, minLines: Int = 1) { BasicTextField( value = value, onValueChange = onValueChange, modifier = modifier .fillMaxWidth() .background(Field, RoundedCornerShape(12.dp)) .border(1.dp, Line, RoundedCornerShape(12.dp)) .padding(horizontal = 14.dp, vertical = 12.dp), textStyle = MaterialTheme.typography.bodyLarge.copy(color = Ink), singleLine = singleLine, minLines = minLines, keyboardOptions = KeyboardOptions( capitalization = KeyboardCapitalization.Sentences, imeAction = if (singleLine) ImeAction.Next else ImeAction.Default ), cursorBrush = SolidColor(Brand), decorationBox = { innerTextField -> Box { if (value.isEmpty()) { Text(text = hint, color = Muted) } innerTextField() } } )}
    @Preview(showBackground = true)@Composablefun NotesScreenPreview() { NotesTheme { NotesScreen() }}

    Same layout as Part 2, dressed. b reads what is new.

  2. What is new, line by line.

    kotlin+java › com.yourname.notes › NotesScreen.ktRead only
    package com.yourname.notes
    import androidx.compose.foundation.Imageimport androidx.compose.foundation.backgroundimport androidx.compose.foundation.borderimport androidx.compose.foundation.layout.Boximport androidx.compose.foundation.layout.Columnimport androidx.compose.foundation.layout.Rowimport androidx.compose.foundation.layout.fillMaxSizeimport androidx.compose.foundation.layout.fillMaxWidthimport androidx.compose.foundation.layout.heightimport androidx.compose.foundation.layout.paddingimport androidx.compose.foundation.layout.sizeimport androidx.compose.foundation.layout.widthimport androidx.compose.foundation.shape.RoundedCornerShapeimport androidx.compose.foundation.text.BasicTextFieldimport androidx.compose.foundation.text.KeyboardOptionsimport androidx.compose.material3.Buttonimport androidx.compose.material3.MaterialThemeimport androidx.compose.material3.Textimport androidx.compose.material3.TextButtonimport androidx.compose.runtime.Composableimport androidx.compose.ui.Alignmentimport androidx.compose.ui.Modifierimport androidx.compose.ui.draw.clipimport androidx.compose.ui.draw.shadowimport androidx.compose.ui.graphics.Brushimport androidx.compose.ui.graphics.SolidColorimport androidx.compose.ui.res.painterResourceimport androidx.compose.ui.text.font.FontWeightimport androidx.compose.ui.text.input.ImeActionimport androidx.compose.ui.text.input.KeyboardCapitalizationimport androidx.compose.ui.text.style.TextAlignimport androidx.compose.ui.tooling.preview.Previewimport androidx.compose.ui.unit.dpimport androidx.compose.ui.unit.emimport androidx.compose.ui.unit.spimport com.yourname.notes.ui.theme.Brandimport com.yourname.notes.ui.theme.CardWhiteimport com.yourname.notes.ui.theme.Fieldimport com.yourname.notes.ui.theme.HeaderEndimport com.yourname.notes.ui.theme.Inkimport com.yourname.notes.ui.theme.Lineimport com.yourname.notes.ui.theme.Mutedimport com.yourname.notes.ui.theme.NotesThemeimport com.yourname.notes.ui.theme.OnBrand
    @Composablefun NotesScreen(modifier: Modifier = Modifier) { Column(modifier = modifier.fillMaxSize()) { Box { // The header Column( modifier = Modifier .padding(16.dp) .fillMaxWidth() .height(168.dp) .background(Brand) .padding(start = 16.dp, top = 20.dp) ) { Image( painter = painterResource(R.drawable.ic_launcher_foreground), contentDescription = "Notes logo", modifier = Modifier.size(36.dp) ) Row(modifier = Modifier.padding(top = 4.dp)) { Text( text = "Notes", color = OnBrand, fontSize = 30.sp, fontWeight = FontWeight.Black, modifier = Modifier.alignByBaseline() ) Text( text = "0", color = Brand, fontSize = 14.sp, fontWeight = FontWeight.Bold, modifier = Modifier .padding(start = 8.dp) .alignByBaseline() .background(CardWhite, RoundedCornerShape(12.dp)) .padding(horizontal = 10.dp, vertical = 2.dp) ) } }
    // The composer: a white card that overlaps the header Column( modifier = Modifier .padding(start = 32.dp, top = 136.dp, end = 32.dp) .fillMaxWidth() .shadow(6.dp, RoundedCornerShape(20.dp)) .background(CardWhite) .padding(16.dp) ) { NotesField( value = "", onValueChange = { }, hint = "Title", singleLine = true ) NotesField( value = "", onValueChange = { }, hint = "Write something…", minLines = 3, modifier = Modifier.padding(top = 8.dp) ) Row( modifier = Modifier.padding(top = 8.dp), verticalAlignment = Alignment.CenterVertically ) { Text( text = "0 / 140", color = Muted, fontSize = 12.sp, modifier = Modifier.weight(1f) ) TextButton( onClick = { }, modifier = Modifier.width(88.dp) ) { Text("Clear") } Button( onClick = { }, shape = RoundedCornerShape(12.dp), modifier = Modifier .padding(start = 4.dp) .width(88.dp) ) { Text("Add") } } } }
    // The list's title, and its hint on the right Row(modifier = Modifier.padding(start = 32.dp, top = 24.dp, end = 32.dp)) { Text( text = "YOUR NOTES", color = Muted, fontSize = 12.sp, fontWeight = FontWeight.Bold, letterSpacing = 0.1.em, modifier = Modifier.alignByBaseline() ) Text( text = "Tap to open · hold to delete", color = Muted, fontSize = 12.sp, textAlign = TextAlign.End, modifier = Modifier .padding(start = 16.dp) .weight(1f) .alignByBaseline() ) } }}
    // Lab 1's style NotesField, as a function: the same look for both text fields@Composablefun NotesField( value: String, onValueChange: (String) -> Unit, hint: String, modifier: Modifier = Modifier, singleLine: Boolean = false, minLines: Int = 1) { BasicTextField( value = value, onValueChange = onValueChange, modifier = modifier .fillMaxWidth() .background(Field, RoundedCornerShape(12.dp)) .border(1.dp, Line, RoundedCornerShape(12.dp)) .padding(horizontal = 14.dp, vertical = 12.dp), textStyle = MaterialTheme.typography.bodyLarge.copy(color = Ink), singleLine = singleLine, minLines = minLines, keyboardOptions = KeyboardOptions( capitalization = KeyboardCapitalization.Sentences, imeAction = if (singleLine) ImeAction.Next else ImeAction.Default ), cursorBrush = SolidColor(Brand), decorationBox = { innerTextField -> Box { if (value.isEmpty()) { Text(text = hint, color = Muted) } innerTextField() } } )}
    @Preview(showBackground = true)@Composablefun NotesScreenPreview() { NotesTheme { NotesScreen() }}
    1. The pill: background, then padding: the space is inside the white, around the count.
    2. shadow(6.dp, …): Lab 1’s elevation 6, with the card’s 20 dp corners.
    3. NotesField, Lab 1’s field style as a function. (String) -> Unit: a parameter that is a function; it receives the new text. Part 5 uses it.
    4. .copy(color = Ink): the theme’s text style, with one change, the colour.
    5. decorationBox: the hint while the field is empty, then innerTextField(), the text itself.
  3. The dressed screen, in the preview and on the phone.

    1. Click Split, at the top right of the editor: NotesScreenPreview appears.
    2. A banner says a build is needed? Click Build & Refresh.
    3. Click ▶ Run 'app'.
    Split previewFull size
    NotesScreenPreview after step 3.2: the flat orange header with the robot, Notes and the white pill 0; the card with its shadow, the Title and Write something… fields, 0 / 140, Clear and an orange Add; YOUR NOTES and its hint.
The phone after step 3.2: the flat orange header with the robot and the pill 0, the floating card with rounded Title and Write something… fields, 0 / 140, Clear and an orange Add, on paper.

You should see Rounded fields with their hints, the card’s shadow, the pill 0. The header is still flat, with the robot.

Done I see Title and Write something… in rounded fields, and the pill 0.

Stuck? 3 symptoms · the file
  • Unresolved reference 'Brand'., then 'CardWhite', 'Field'…, in NotesScreen.kt Step 3.1’s Color.kt is missing. Do step 3.1 first.
  • A successful build is needed before the preview can be displayed The preview needs one build. Click Build & Refresh.
  • The fields are still grey boxes The paste went into another file. Click the NotesScreen.kt tab, then paste again.

The file at the end of this step is the panel of action a: Copy the file.

Step 3 of 3

Paint the header with a gradient, then add the logo

10 min

Goal Type the header’s two paint links and switch to Lab 1’s logo: your screen then matches Lab 1’s.

  • Resources res › drawable › ic_notes.xml
  • Kotlin NotesScreen.kt · Split
  • Emulator
  1. A new file for Lab 1’s logo: ic_notes.xml, in res › drawable.

    1. In the Project window, right-click res › drawable, then choose NewDrawable Resource File.
    2. A New Resource File window opens: in File name, type ic_notes, then click OK.
    3. ic_notes.xml opens in Design: click Code.
  2. Paste The logo: Lab 1’s white sticky note.

    1. Click Copy the file on the panel below.
    2. Click in its text, press Ctrl+A, then Ctrl+V.
    res › drawable › ic_notes.xmlNew file
    <!--  ~ Copyright (C) 2026 The Android Open Source Project  ~  ~ Licensed under the Apache License, Version 2.0 (the "License");  ~ you may not use this file except in compliance with the License.  ~ You may obtain a copy of the License at  ~  ~      http://www.apache.org/licenses/LICENSE-2.0  ~  ~ Unless required by applicable law or agreed to in writing, software  ~ distributed under the License is distributed on an "AS IS" BASIS,  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  ~ See the License for the specific language governing permissions and  ~ limitations under the License.  --><vector xmlns:android="http://schemas.android.com/apk/res/android" android:autoMirrored="true" android:height="24dp" android:tint="#FFFFFF" android:viewportHeight="24" android:viewportWidth="24" android:width="24dp">          <path android:fillColor="@android:color/white" android:pathData="M19,3H4.99C3.89,3 3,3.9 3,5l0.01,14c0,1.1 0.89,2 1.99,2h10l6,-6V5C21,3.9 20.1,3 19,3zM7,8h10v2H7V8zM12,14H7v-2h5V14zM14,19.5V14h5.5L14,19.5z"/>    </vector>

    Lab 1’s file, as Asset Studio wrote it.

  3. Type The header’s paint: round corners, then a gradient, then the logo.

    1. Click the NotesScreen.kt tab. At the end of line 52, // The header, type : a gradient with round corners.
    2. Click at the end of line 57, .height(168.dp), press Enter, then type .clip(RoundedCornerShape(28.dp)).
    3. On line 59, double-click Brand in .background(Brand), then type Brush.linearGradient(listOf(Brand, HeaderEnd)).
    4. On line 63, double-click ic_launcher_foreground, then type ic_notes.
    5. A list opens while you type? Press Esc. Android Studio adds each closing bracket: type it anyway, it steps over.
    kotlin+java › com.yourname.notes › NotesScreen.ktEdit the marked lines
    package com.yourname.notes
    import androidx.compose.foundation.Imageimport androidx.compose.foundation.backgroundimport androidx.compose.foundation.borderimport androidx.compose.foundation.layout.Boximport androidx.compose.foundation.layout.Columnimport androidx.compose.foundation.layout.Rowimport androidx.compose.foundation.layout.fillMaxSizeimport androidx.compose.foundation.layout.fillMaxWidthimport androidx.compose.foundation.layout.heightimport androidx.compose.foundation.layout.paddingimport androidx.compose.foundation.layout.sizeimport androidx.compose.foundation.layout.widthimport androidx.compose.foundation.shape.RoundedCornerShapeimport androidx.compose.foundation.text.BasicTextFieldimport androidx.compose.foundation.text.KeyboardOptionsimport androidx.compose.material3.Buttonimport androidx.compose.material3.MaterialThemeimport androidx.compose.material3.Textimport androidx.compose.material3.TextButtonimport androidx.compose.runtime.Composableimport androidx.compose.ui.Alignmentimport androidx.compose.ui.Modifierimport androidx.compose.ui.draw.clipimport androidx.compose.ui.draw.shadowimport androidx.compose.ui.graphics.Brushimport androidx.compose.ui.graphics.SolidColorimport androidx.compose.ui.res.painterResourceimport androidx.compose.ui.text.font.FontWeightimport androidx.compose.ui.text.input.ImeActionimport androidx.compose.ui.text.input.KeyboardCapitalizationimport androidx.compose.ui.text.style.TextAlignimport androidx.compose.ui.tooling.preview.Previewimport androidx.compose.ui.unit.dpimport androidx.compose.ui.unit.emimport androidx.compose.ui.unit.spimport com.yourname.notes.ui.theme.Brandimport com.yourname.notes.ui.theme.CardWhiteimport com.yourname.notes.ui.theme.Fieldimport com.yourname.notes.ui.theme.HeaderEndimport com.yourname.notes.ui.theme.Inkimport com.yourname.notes.ui.theme.Lineimport com.yourname.notes.ui.theme.Mutedimport com.yourname.notes.ui.theme.NotesThemeimport com.yourname.notes.ui.theme.OnBrand
    @Composablefun NotesScreen(modifier: Modifier = Modifier) { Column(modifier = modifier.fillMaxSize()) { Box { // The header // The header: a gradient with round corners Column( modifier = Modifier .padding(16.dp) .fillMaxWidth() .height(168.dp) .background(Brand) .clip(RoundedCornerShape(28.dp)) .background(Brush.linearGradient(listOf(Brand, HeaderEnd))) .padding(start = 16.dp, top = 20.dp) ) { Image( painter = painterResource(R.drawable.ic_launcher_foreground), painter = painterResource(R.drawable.ic_notes), contentDescription = "Notes logo", modifier = Modifier.size(36.dp) ) Row(modifier = Modifier.padding(top = 4.dp)) { Text( text = "Notes", color = OnBrand, fontSize = 30.sp, fontWeight = FontWeight.Black, modifier = Modifier.alignByBaseline() ) Text( text = "0", color = Brand, fontSize = 14.sp, fontWeight = FontWeight.Bold, modifier = Modifier .padding(start = 8.dp) .alignByBaseline() .background(CardWhite, RoundedCornerShape(12.dp)) .padding(horizontal = 10.dp, vertical = 2.dp) ) } }
    // The composer: a white card that overlaps the header Column( modifier = Modifier .padding(start = 32.dp, top = 136.dp, end = 32.dp) .fillMaxWidth() .shadow(6.dp, RoundedCornerShape(20.dp)) .background(CardWhite) .padding(16.dp) ) { NotesField( value = "", onValueChange = { }, hint = "Title", singleLine = true ) NotesField( value = "", onValueChange = { }, hint = "Write something…", minLines = 3, modifier = Modifier.padding(top = 8.dp) ) Row( modifier = Modifier.padding(top = 8.dp), verticalAlignment = Alignment.CenterVertically ) { Text( text = "0 / 140", color = Muted, fontSize = 12.sp, modifier = Modifier.weight(1f) ) TextButton( onClick = { }, modifier = Modifier.width(88.dp) ) { Text("Clear") } Button( onClick = { }, shape = RoundedCornerShape(12.dp), modifier = Modifier .padding(start = 4.dp) .width(88.dp) ) { Text("Add") } } } }
    // The list's title, and its hint on the right Row(modifier = Modifier.padding(start = 32.dp, top = 24.dp, end = 32.dp)) { Text( text = "YOUR NOTES", color = Muted, fontSize = 12.sp, fontWeight = FontWeight.Bold, letterSpacing = 0.1.em, modifier = Modifier.alignByBaseline() ) Text( text = "Tap to open · hold to delete", color = Muted, fontSize = 12.sp, textAlign = TextAlign.End, modifier = Modifier .padding(start = 16.dp) .weight(1f) .alignByBaseline() ) } }}
    // Lab 1's style NotesField, as a function: the same look for both text fields@Composablefun NotesField( value: String, onValueChange: (String) -> Unit, hint: String, modifier: Modifier = Modifier, singleLine: Boolean = false, minLines: Int = 1) { BasicTextField( value = value, onValueChange = onValueChange, modifier = modifier .fillMaxWidth() .background(Field, RoundedCornerShape(12.dp)) .border(1.dp, Line, RoundedCornerShape(12.dp)) .padding(horizontal = 14.dp, vertical = 12.dp), textStyle = MaterialTheme.typography.bodyLarge.copy(color = Ink), singleLine = singleLine, minLines = minLines, keyboardOptions = KeyboardOptions( capitalization = KeyboardCapitalization.Sentences, imeAction = if (singleLine) ImeAction.Next else ImeAction.Default ), cursorBrush = SolidColor(Brand), decorationBox = { innerTextField -> Box { if (value.isEmpty()) { Text(text = hint, color = Muted) } innerTextField() } } )}
    @Preview(showBackground = true)@Composablefun NotesScreenPreview() { NotesTheme { NotesScreen() }}

    Lines 25, 27 and 41 import clip, Brush and HeaderEnd: they came with 3.2’s paste. linearGradient runs from the top-left corner to the bottom-right one, as Lab 1’s angle="315".

  4. The finished header, in the preview and on the phone.

    1. Look at the preview: the header turns orange to rose, with round corners and the logo.
    2. Click ▶ Run 'app', then compare your phone with Lab 1’s, below.
    Split previewFull size
    NotesScreenPreview after step 3.3: the header is a gradient from orange at the top left to rose at the bottom right, with round corners and the white notes logo above Notes and the pill 0.
Lab 2 at the end of Part 3: the gradient header with round corners, the white logo, Notes and the pill 0, the floating card with its two fields, 0 / 140, Clear and an orange Add, an empty list on paper.
Lab 2 · Compose
Lab 1 at the end of its Part 4, at the same size: the same gradient header, logo, pill, card and orange Add.
Lab 1 · XML

You should see The same screen as Lab 1: the gradient, the logo, the floating card, the pill 0.

Done I see the gradient header with the white logo, as in Lab 1.

Stuck? 3 symptoms · the file
  • Unresolved reference 'ic_notes'. ic_notes.xml is missing from res › drawable, or its name differs. Do actions a and b again.
  • The corners are square .clip(…) is missing, or comes after .background(…): the paint is already done. Put it just before.
  • The gradient runs the other way The list reads listOf(HeaderEnd, Brand). Put Brand first.

Behind? The files at the end of this step

kotlin+java › com.yourname.notes › NotesScreen.ktReplace the whole file
package com.yourname.notes
import androidx.compose.foundation.Imageimport androidx.compose.foundation.backgroundimport androidx.compose.foundation.borderimport androidx.compose.foundation.layout.Boximport androidx.compose.foundation.layout.Columnimport androidx.compose.foundation.layout.Rowimport androidx.compose.foundation.layout.fillMaxSizeimport androidx.compose.foundation.layout.fillMaxWidthimport androidx.compose.foundation.layout.heightimport androidx.compose.foundation.layout.paddingimport androidx.compose.foundation.layout.sizeimport androidx.compose.foundation.layout.widthimport androidx.compose.foundation.shape.RoundedCornerShapeimport androidx.compose.foundation.text.BasicTextFieldimport androidx.compose.foundation.text.KeyboardOptionsimport androidx.compose.material3.Buttonimport androidx.compose.material3.MaterialThemeimport androidx.compose.material3.Textimport androidx.compose.material3.TextButtonimport androidx.compose.runtime.Composableimport androidx.compose.ui.Alignmentimport androidx.compose.ui.Modifierimport androidx.compose.ui.draw.clipimport androidx.compose.ui.draw.shadowimport androidx.compose.ui.graphics.Brushimport androidx.compose.ui.graphics.SolidColorimport androidx.compose.ui.res.painterResourceimport androidx.compose.ui.text.font.FontWeightimport androidx.compose.ui.text.input.ImeActionimport androidx.compose.ui.text.input.KeyboardCapitalizationimport androidx.compose.ui.text.style.TextAlignimport androidx.compose.ui.tooling.preview.Previewimport androidx.compose.ui.unit.dpimport androidx.compose.ui.unit.emimport androidx.compose.ui.unit.spimport com.yourname.notes.ui.theme.Brandimport com.yourname.notes.ui.theme.CardWhiteimport com.yourname.notes.ui.theme.Fieldimport com.yourname.notes.ui.theme.HeaderEndimport com.yourname.notes.ui.theme.Inkimport com.yourname.notes.ui.theme.Lineimport com.yourname.notes.ui.theme.Mutedimport com.yourname.notes.ui.theme.NotesThemeimport com.yourname.notes.ui.theme.OnBrand
@Composablefun NotesScreen(modifier: Modifier = Modifier) { Column(modifier = modifier.fillMaxSize()) { Box { // The header: a gradient with round corners Column( modifier = Modifier .padding(16.dp) .fillMaxWidth() .height(168.dp) .clip(RoundedCornerShape(28.dp)) .background(Brush.linearGradient(listOf(Brand, HeaderEnd))) .padding(start = 16.dp, top = 20.dp) ) { Image( painter = painterResource(R.drawable.ic_notes), contentDescription = "Notes logo", modifier = Modifier.size(36.dp) ) Row(modifier = Modifier.padding(top = 4.dp)) { Text( text = "Notes", color = OnBrand, fontSize = 30.sp, fontWeight = FontWeight.Black, modifier = Modifier.alignByBaseline() ) Text( text = "0", color = Brand, fontSize = 14.sp, fontWeight = FontWeight.Bold, modifier = Modifier .padding(start = 8.dp) .alignByBaseline() .background(CardWhite, RoundedCornerShape(12.dp)) .padding(horizontal = 10.dp, vertical = 2.dp) ) } }
// The composer: a white card that overlaps the header Column( modifier = Modifier .padding(start = 32.dp, top = 136.dp, end = 32.dp) .fillMaxWidth() .shadow(6.dp, RoundedCornerShape(20.dp)) .background(CardWhite) .padding(16.dp) ) { NotesField( value = "", onValueChange = { }, hint = "Title", singleLine = true ) NotesField( value = "", onValueChange = { }, hint = "Write something…", minLines = 3, modifier = Modifier.padding(top = 8.dp) ) Row( modifier = Modifier.padding(top = 8.dp), verticalAlignment = Alignment.CenterVertically ) { Text( text = "0 / 140", color = Muted, fontSize = 12.sp, modifier = Modifier.weight(1f) ) TextButton( onClick = { }, modifier = Modifier.width(88.dp) ) { Text("Clear") } Button( onClick = { }, shape = RoundedCornerShape(12.dp), modifier = Modifier .padding(start = 4.dp) .width(88.dp) ) { Text("Add") } } } }
// The list's title, and its hint on the right Row(modifier = Modifier.padding(start = 32.dp, top = 24.dp, end = 32.dp)) { Text( text = "YOUR NOTES", color = Muted, fontSize = 12.sp, fontWeight = FontWeight.Bold, letterSpacing = 0.1.em, modifier = Modifier.alignByBaseline() ) Text( text = "Tap to open · hold to delete", color = Muted, fontSize = 12.sp, textAlign = TextAlign.End, modifier = Modifier .padding(start = 16.dp) .weight(1f) .alignByBaseline() ) } }}
// Lab 1's style NotesField, as a function: the same look for both text fields@Composablefun NotesField( value: String, onValueChange: (String) -> Unit, hint: String, modifier: Modifier = Modifier, singleLine: Boolean = false, minLines: Int = 1) { BasicTextField( value = value, onValueChange = onValueChange, modifier = modifier .fillMaxWidth() .background(Field, RoundedCornerShape(12.dp)) .border(1.dp, Line, RoundedCornerShape(12.dp)) .padding(horizontal = 14.dp, vertical = 12.dp), textStyle = MaterialTheme.typography.bodyLarge.copy(color = Ink), singleLine = singleLine, minLines = minLines, keyboardOptions = KeyboardOptions( capitalization = KeyboardCapitalization.Sentences, imeAction = if (singleLine) ImeAction.Next else ImeAction.Default ), cursorBrush = SolidColor(Brand), decorationBox = { innerTextField -> Box { if (value.isEmpty()) { Text(text = hint, color = Muted) } innerTextField() } } )}
@Preview(showBackground = true)@Composablefun NotesScreenPreview() { NotesTheme { NotesScreen() }}

If it doesn’t work

  • White icons at the top, hard to see on paper The phone is in dark mode; this theme is light only. Part 7 adds these lines. To fix it now, paste them in MainActivity.kt, import first. A later MainActivity.kt from a catch-up box or a Stuck? fold drops them again.
    kotlin+java › com.yourname.notes › MainActivity.ktAdd the marked lines
    package com.yourname.notes
    import android.os.Bundleimport androidx.activity.ComponentActivityimport androidx.activity.compose.setContentimport androidx.activity.enableEdgeToEdgeimport androidx.compose.foundation.layout.WindowInsetsimport androidx.compose.foundation.layout.fillMaxSizeimport androidx.compose.foundation.layout.paddingimport androidx.compose.foundation.layout.safeDrawingimport androidx.compose.material3.Scaffoldimport androidx.compose.ui.Modifierimport androidx.core.view.WindowCompatimport com.yourname.notes.ui.theme.NotesTheme
    class MainActivity : ComponentActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) enableEdgeToEdge() // Dark icons on the paper, even when the phone is in dark mode (Lab 1's windowLightStatusBar) val bars = WindowCompat.getInsetsController(window, window.decorView) bars.isAppearanceLightStatusBars = true bars.isAppearanceLightNavigationBars = true setContent { NotesTheme { Scaffold( modifier = Modifier.fillMaxSize(), // keep the screen out of the status bar, the gesture bar and the keyboard contentWindowInsets = WindowInsets.safeDrawing ) { innerPadding -> NotesScreen(modifier = Modifier.padding(innerPadding)) } } } }}
  • Red names right after a paste The paste went into another file. Each panel’s bar names its file: open that one, select all, paste again.
  • A colour changed in Color.kt but not on the phone The composable names another colour, or Android Studio still shows the old run. Click ▶ again.

Now you If you have time

Your own palette, in two lines

In Color.kt, change the values of Brand (line 6) and HeaderEnd (line 8) to a palette below, then ▶. What follows?

The palettes, with their two colours
PaletteBrandHeaderEnd
1Ocean0xFF0369A10xFF4F46E5
2Forest0xFF0478570xFF0E7490
3Berry0xFFBE185D0xFF7C3AED
4Sunset, the page’s0xFFC2410C0xFFE11D48
See the answer

For Ocean: val Brand = Color(0xFF0369A1) and val HeaderEnd = Color(0xFF4F46E5). The header, Add, Clear, the cursor and the count follow: they read Brand by name or through the theme. Then type Sunset back: the next parts’ captures use it.

Go deeper Texts in strings.xml, as in Lab 1

Compose reads Lab 1’s strings too: Text(stringResource(R.string.add)). This lab keeps English literals, so one set of captures serves both languages.

End of the part

Recap

Your wallpaper chose Add’s colour: the template’s theme had dynamic colour on. Now NotesTheme hands Lab 1’s palette to everything inside it, and each shape is a Modifier chain, read top to bottom.

  • say where a composable gets its colours: from the theme, unless its code names one;
  • move a palette into Color.kt and a light theme;
  • paint a box link by link: corners, a gradient, a border, a shadow.
Your app at the end of Part 3: the gradient header with the white logo and the pill 0, the floating card, an empty list, on paper.
Your app now