The idea: three containers, and a Modifier
Lab 1 placed each view with constraints. In Compose you nest containers: each one holds the next pieces between its { } (Kotlin sheet, card 8).
Lab 1: a vertical LinearLayout
Column
Stacks its pieces, top to bottom.
Lab 1: a horizontal LinearLayout
Row
Lines them up, left to right.
Lab 1: a FrameLayout
Box
Lays them one over the other: the last one on top.
Modifier.The screen you build, container by container
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() }}- The screen: a
Column. The Box, then the title row, one under the other. - A
Box: the band and the card, one over the other. - The band: a
Column, the logo over the title row. - A
Row: Notes and its count, on one baseline. - The card: a
Column, drawn over the band because it comes last in the Box. - A
Row: the counter takes the free space, Clear and Add keep their width. - A
Row: YOUR NOTES, and the hint at the right.
Read the Modifier top to bottom
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() }}paddingfirst: 16 dp left empty around the band. A margin.- 168 dp high, across the whole width.
backgroundpaints what is left.paddingafter the paint: the logo starts 16 dp from the left and 20 from the top, inside the orange.
background is a margin; after it, a padding (Kotlin sheet, card 9).Lab 1 The same band in XML 1 min
<?xml version="1.0" encoding="utf-8"?><androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:fitsSystemWindows="true" tools:context=".MainActivity">
<View android:id="@+id/header" android:layout_width="0dp" android:layout_height="168dp" android:layout_marginStart="16dp" android:layout_marginTop="16dp" android:layout_marginEnd="16dp" android:background="#C2410C" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" />
<ImageView android:id="@+id/imageLogo" android:layout_width="36dp" android:layout_height="36dp" android:layout_marginStart="16dp" android:layout_marginTop="20dp" android:contentDescription="Notes logo" app:layout_constraintStart_toStartOf="@id/header" app:layout_constraintTop_toTopOf="@id/header" app:srcCompat="@drawable/ic_launcher_foreground" />
<TextView android:id="@+id/textAppTitle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="4dp" android:text="Notes" android:textColor="#FFFFFF" android:textSize="30sp" app:layout_constraintStart_toStartOf="@id/imageLogo" app:layout_constraintTop_toBottomOf="@id/imageLogo" />
<TextView android:id="@+id/textCount" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginStart="8dp" android:text="0" android:textColor="#FFFFFF" android:textSize="14sp" app:layout_constraintBaseline_toBaselineOf="@id/textAppTitle" app:layout_constraintStart_toEndOf="@id/textAppTitle" />
<LinearLayout android:id="@+id/composer" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_marginStart="32dp" android:layout_marginTop="120dp" android:layout_marginEnd="32dp" android:background="#FFFFFF" android:orientation="vertical" android:padding="16dp" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="@id/header">
<EditText android:id="@+id/editTitle" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="Title" android:importantForAutofill="no" android:inputType="textCapSentences" />
<EditText android:id="@+id/editBody" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="8dp" android:gravity="top" android:hint="Write something…" android:importantForAutofill="no" android:inputType="textMultiLine|textCapSentences" android:maxLength="140" android:minLines="3" />
<TextView android:id="@+id/textError" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="8dp" android:text="Give your note a title first." android:textSize="14sp" android:visibility="gone" />
<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="8dp" android:gravity="center_vertical" android:orientation="horizontal">
<TextView android:id="@+id/textCounter" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="0 / 140" android:textSize="12sp" />
<Button android:id="@+id/buttonClear" style="@style/Widget.Material3.Button.TextButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Clear" />
<Button android:id="@+id/buttonAdd" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginStart="4dp" android:text="Add" /> </LinearLayout> </LinearLayout>
<TextView android:id="@+id/textListTitle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginStart="32dp" android:layout_marginTop="24dp" android:text="YOUR NOTES" android:textSize="12sp" android:textStyle="bold" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/composer" />
<TextView android:id="@+id/textListHint" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_marginStart="16dp" android:layout_marginEnd="32dp" android:gravity="end" android:text="Tap to open · hold to delete" android:textSize="12sp" app:layout_constraintBaseline_toBaselineOf="@id/textListTitle" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toEndOf="@id/textListTitle" />
<ScrollView android:id="@+id/scrollNotes" android:layout_width="0dp" android:layout_height="0dp" android:layout_marginTop="8dp" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/textListHint">
<LinearLayout android:id="@+id/notesContainer" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" android:paddingStart="16dp" android:paddingEnd="16dp" android:paddingBottom="16dp" /> </ScrollView>
<TextView android:id="@+id/textEmpty" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="48dp" android:gravity="center" android:text="No notes yet.\nWrite your first one above." android:textSize="16sp" android:visibility="gone" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="@id/scrollNotes" />
</androidx.constraintlayout.widget.ConstraintLayout>- The height, 168dp.
- The margin: three attributes. In Compose, one
paddingbefore the paint. - The colour. In Compose,
background. - The count on the title’s baseline. In Compose,
alignByBaseline()in a Row. - The card starts 120dp under the band’s top, so it overlaps. In Compose, a Box and
top = 136.dp. - The padding inside the card. In Compose, a
paddingafter the paint.
Part 1 not finished, or a fresh project? Start here about 3 min
The project: your own from Part 1, or a fresh one: Part 0, steps 0.2 to 0.4 (about 10 minutes).
Your package name, for the code of this page:
Without JavaScript, the code says com.yourname.notes: replace yourname by the name you chose.
Kotlin: open MainActivity.kt, select all, then paste this file.
kotlin+java › com.yourname.notes › MainActivity.ktReplace the whole filepackage com.yourname.notes
import android.os.Bundleimport androidx.activity.ComponentActivityimport androidx.activity.compose.setContentimport androidx.activity.enableEdgeToEdgeimport androidx.compose.foundation.layout.fillMaxSizeimport androidx.compose.foundation.layout.paddingimport androidx.compose.material3.Scaffoldimport androidx.compose.material3.Textimport androidx.compose.runtime.Composableimport androidx.compose.ui.Modifierimport androidx.compose.ui.tooling.preview.Previewimport com.yourname.notes.ui.theme.NotesTheme
class MainActivity : ComponentActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) enableEdgeToEdge() setContent { NotesTheme { Scaffold(modifier = Modifier.fillMaxSize()) { innerPadding -> Greeting( name = "Notes", modifier = Modifier.padding(innerPadding) ) } } } }}
@Composablefun Greeting(name: String, modifier: Modifier = Modifier) { Text( text = "Hello, $name!", modifier = modifier )}
@Preview(showBackground = true)@Composablefun GreetingPreview() { NotesTheme { Greeting("Notes") }}Restarting this part? Also delete
NotesScreen.kt(right-click it, Delete…, OK) before step 2.1.▶. You are ready when the phone shows “Hello, Notes!” at the top left.
- 2.2 the band, the logo, the title
- 2.3 the card over the band
- 2.4 the list’s title row
Before you start
By the end you can
- stack, line up and overlap pieces with
Column,RowandBox; - size and space a piece with a
Modifier, in the right order; - call your own screen from the activity.
- Kotlin kotlin+java › com.yourname.notes
- Android Studio Split · preview
- Emulator
No layout file this time: the whole screen is Kotlin.
Step 1 of 5
Create the screen’s file
Goal A new file, NotesScreen.kt: one composable function with an empty Column, and its preview.
- Android Studio Project
- Kotlin kotlin+java › com.yourname.notes › NotesScreen.kt
-
A new Kotlin file.
- In the Project window, right-click kotlin+java › com.yourname.notes, the one without
(test). - Click NewKotlin Class/File.
- A New Kotlin Class/File window opens: type
NotesScreen, click File in the list, then press Enter. - NotesScreen.kt opens with
package com.yourname.noteson line 1, and an empty line 2 under it.
New Kotlin Class/File A dialogFull size
- The name:
NotesScreen. - File: a file for functions, not a class.
- In the Project window, right-click kotlin+java › com.yourname.notes, the one without
-
Paste The imports of the whole part, first.
- On the panel, click Copy 26 lines.
- Click at the end of line 2, the empty line under
package, press Enter, then Ctrl+V. - The imports are grey: not used yet. The next steps use them; nothing should be red.
kotlin+java › com.yourname.notes › NotesScreen.ktAdd the marked linespackage 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 -
Type The function, and its preview.
- Click at the end of line 28, press Enter twice, then type lines 30 to 32.
- Line 32 ends with
{}: Android Studio closed the brace for you. - A list of suggestions opens as you type? Press Esc before Enter: with the list open, Enter picks a suggestion and stays on the line.
- Each
{you type brings its}: the grey lines arrive by themselves. An empty line more or less changes nothing. - Click after the last
}of the file, press Enter twice, then type lines 35 to 39.
kotlin+java › com.yourname.notes › NotesScreen.ktAdd the marked linespackage 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()) {}}
@Preview(showBackground = true)@Composablefun NotesScreenPreview() { NotesTheme { NotesScreen() }}The shape of Part 1’s
Greeting.modifier: Modifier = Modifier: a parameter with a default value (Kotlin sheet, card 6); line 32 passes it to the Column.
Done NotesScreen.kt shows no red: one function and its preview.
Stuck? 2 symptoms · the file
- The file holds
class NotesScreen {You picked Class. Delete the class’s lines, keeppackage, then go on with the paste. - A name is red:
Unresolved referenceAn import is missing. Paste the file below over yours.
Behind? The files at the end of this step
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()) {}}
@Preview(showBackground = true)@Composablefun NotesScreenPreview() { NotesTheme { NotesScreen() }}Step 2 of 5
Build the band: a Column and its Modifier
Goal In a Box, the orange band: the logo, then Notes and its count on one line.
- Kotlin NotesScreen.kt
- Android Studio Split · preview
-
Type The band: a Column, sized and spaced by its Modifier.
- Click between the
{and the}at the end of line 32,Column(…) {}, then press Enter. - Type lines 33 to 41, one Modifier call per line; Esc before Enter if a list is open. The
)of line 42 arrives by itself. - Press ↓, then End, and type
{: its}comes by itself.
kotlin+java › com.yourname.notes › NotesScreen.ktAdd the marked linespackage 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) ) {} } }}
@Preview(showBackground = true)@Composablefun NotesScreenPreview() { NotesTheme { NotesScreen() }}16.dp: a size that looks the same on every screen, as in Lab 1 (card 9). The colour is written here by hand until Part 3. - Click between the
-
Paste The logo, inside the band.
- Click Copy 5 lines, then click between the
{and the}of line 42,) {}. - Press Enter, then Ctrl+V.
kotlin+java › com.yourname.notes › NotesScreen.ktAdd the marked linespackage 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) ) } } }}
@Preview(showBackground = true)@Composablefun NotesScreenPreview() { NotesTheme { NotesScreen() }}painterResourcereads a picture fromres/drawable: Compose still uses it. The launcher’s Android head stands in for the logo until Part 3. - Click Copy 5 lines, then click between the
-
Type The title row: Notes and its count, on one baseline.
- Click at the end of line 47, the
)that closesImage(, then press Enter. - Type lines 48 to 53; Esc before Enter if a list is open.
30.spis a text size (card 9). - Press ↓, End, then Enter, and type lines 55 to 60. The grey lines arrive by themselves.
kotlin+java › com.yourname.notes › NotesScreen.ktAdd the marked linespackage 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() ) } } } }}
@Preview(showBackground = true)@Composablefun NotesScreenPreview() { NotesTheme { NotesScreen() }} - Click at the end of line 47, the
-
See it in the preview.
- Click Split, at the top right of the editor.
- The preview asks for a build? Click Build & Refresh, as in Part 1.
Preview EditorFull size
Done In the preview: an orange band, the Android head, then Notes and a small 0.
Stuck? 3 symptoms · the file
- The band touches the preview’s edges
.padding(16.dp)is not first in the chain. Move it back above.fillMaxWidth(). - The 0 sits higher than the letters of Notes One
alignByBaseline()is missing: both Texts need it. - A red
}near the end of the file One}too many, or one missing. Compare with the file below.
Behind? The files at the end of this step
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() ) } } } }}
@Preview(showBackground = true)@Composablefun NotesScreenPreview() { NotesTheme { NotesScreen() }}Step 3 of 5
Lay the card over the band
Goal Paste the white card into the Box, after the band: it covers the band’s lower part.
- Kotlin NotesScreen.kt
-
Paste The card: a white Column, two fields and a row.
- Click Copy 37 lines, then click at the end of line 63, the
}that closes the band. - Press Enter, then Ctrl+V.
kotlin+java › com.yourname.notes › NotesScreen.ktAdd the marked linespackage 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") } } } } }}
@Preview(showBackground = true)@Composablefun NotesScreenPreview() { NotesTheme { NotesScreen() }}top = 136.dp: 16 of margin + 120, so the card starts inside the band.value = "": the fields show an empty text (Part 5).weight(1f): the counter takes the free space, like Lab 1’s0dp. - Click Copy 37 lines, then click at the end of line 63, the
Why A Box draws its pieces one over the other, the last on top: the card comes after the band, so it covers it.
Done In the preview: the white card over the band’s lower edge, two grey boxes, 0 / 140, Clear and Add.
Stuck? 2 symptoms · the file
- The card sits under the band, not over it You pasted after the Box’s
}: the screen’s Column stacks it. Cut it, and paste it after the band’s}, insideBox {. - The band covers the card The card comes before the band in the Box. Move it after the band: the last piece is on top.
Behind? The files at the end of this step
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") } } } } }}
@Preview(showBackground = true)@Composablefun NotesScreenPreview() { NotesTheme { NotesScreen() }}Step 4 of 5
Line up the list’s title
Goal Under the Box, a Row: YOUR NOTES at the left, the hint stretched to the right.
- Kotlin NotesScreen.kt
- Android Studio Split · preview
-
Type The row, with YOUR NOTES.
- Click at the end of line 101, the
}that closes the Box, then press Enter. - Type the marked lines; Esc before Enter if a list is open. The grey
}arrives by itself.
kotlin+java › com.yourname.notes › NotesScreen.ktAdd the marked linespackage 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()) } }}
@Preview(showBackground = true)@Composablefun NotesScreenPreview() { NotesTheme { NotesScreen() }} - Click at the end of line 101, the
-
Paste The hint, beside it.
- Click Copy 8 lines, then click at the end of line 105, the YOUR NOTES line.
- Press Enter, then Ctrl+V. Look at the preview.
Preview EditorFull size
kotlin+java › com.yourname.notes › NotesScreen.ktAdd the marked linespackage 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() }}weight(1f): the hint fills the free space, like Lab 1’s0dp.TextAlign.Endputs its words at the right.
Done In the preview: YOUR NOTES at the left, the hint at the right, on one line.
Stuck? 2 symptoms · the file
- The hint sits right after YOUR NOTES Its
.weight(1f)is missing: without it, the hint takes only the room of its words. - The row is inside the card You typed it before the Box’s
}. It goes after it, in the screen’s Column.
Behind? The files at the end of this step
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() }}Step 5 of 5
Show your screen on the phone
Goal The activity calls NotesScreen instead of Greeting; the phone shows Lab 2’s own skeleton.
- Kotlin kotlin+java › com.yourname.notes › MainActivity.kt
- Emulator
-
Type Call your screen.
- Open MainActivity.kt. Select lines 23 to 26, from
Greeting(to its). - Type the marked line in their place.
kotlin+java › com.yourname.notes › MainActivity.ktAdd the marked linespackage com.yourname.notes
import android.os.Bundleimport androidx.activity.ComponentActivityimport androidx.activity.compose.setContentimport androidx.activity.enableEdgeToEdgeimport androidx.compose.foundation.layout.fillMaxSizeimport androidx.compose.foundation.layout.paddingimport androidx.compose.material3.Scaffoldimport androidx.compose.material3.Textimport androidx.compose.runtime.Composableimport androidx.compose.ui.Modifierimport androidx.compose.ui.tooling.preview.Previewimport com.yourname.notes.ui.theme.NotesTheme
class MainActivity : ComponentActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) enableEdgeToEdge() setContent { NotesTheme { Scaffold(modifier = Modifier.fillMaxSize()) { innerPadding -> NotesScreen(modifier = Modifier.padding(innerPadding)) } } } }}
@Composablefun Greeting(name: String, modifier: Modifier = Modifier) { Text( text = "Hello, $name!", modifier = modifier )}
@Preview(showBackground = true)@Composablefun GreetingPreview() { NotesTheme { Greeting("Notes") }} - Open MainActivity.kt. Select lines 23 to 26, from
-
Paste The system bars, and Greeting gone.
- Click Copy the file. In MainActivity.kt, press Ctrl+A, then Ctrl+V.
- Your
NotesScreen(…)line is in it, unchanged. Greeting and its preview are gone.
kotlin+java › com.yourname.notes › MainActivity.ktReplace the whole filepackage 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)) } } } }}WindowInsets.safeDrawing: the Scaffold keeps the screen out of the status bar, the gesture bar and the keyboard.innerPaddinghands that space to NotesScreen. -
▶ Run 'app'.
-
Try to write a title.
- On the phone, tap the first grey box, then type a letter.
- Nothing appears. Part 5 says why.

You should see Lab 2’s own skeleton: grey boxes without hints, Add in your wallpaper’s colour. The hints, the colours and the type sizes arrive in Part 3.
Done I see the skeleton, and the first box refuses my letters.
Stuck? 3 symptoms · the file
- The band goes up behind the status bar’s clock
NotesScreenlostmodifier = Modifier.padding(innerPadding). Paste b’s file again. - The phone still says “Hello, Notes!” The paste did not replace the file. Press Ctrl+A before Ctrl+V, then ▶ again.
- Add is blue or purple, not orange Normal: from Android 12, colours come from your wallpaper. Part 3 turns that off.
The file at the end of this step is b’s panel: Copy the file. NotesScreen.kt is in 2.4’s Stuck? fold.
If it doesn’t work
- A red name Click the name and press Alt+Enter › Import. If a list opens, take the
androidx.compose…line, neverandroid.graphics,android.media,android.widgetorjava.lang.reflect. Almost every name red inNotesScreen.kt? 2.1’s imports were skipped: paste them once, after line 2 (2.1, action b). Conflicting import: imported name '…' is ambiguousAn import line is there twice: the imports were pasted again. Delete the second copy, or open the last done step’s Stuck? fold and paste its file.Too many arguments for constructor(): ColororUnresolved reference WhiteColorcame fromandroid.graphics. Its line must readimport androidx.compose.ui.graphics.Color.Cannot create an instance of an abstract classonImageImagecame fromandroid.media. Its line must readimport androidx.compose.foundation.Image.None of the following candidates is applicableonButton, withconstructor(p0: Context!)Buttoncame fromandroid.widget. Its line must readimport androidx.compose.material3.Button.Classifier class Modifier does not have a companion objectModifiercame fromjava.lang.reflect. Its line must readimport androidx.compose.ui.Modifier.- A successful build is needed before the preview can be displayed Click Build & Refresh in the preview.
End of the part
Recap
No sixteen constraints: three containers placed the screen. A Column stacks, a Row lines up, a Box overlaps. The Modifier, read top to bottom, sizes and spaces each piece.
- stack, line up and overlap pieces with
Column,RowandBox; - size and space a piece with a
Modifier, in the right order; - call your own screen from the activity.

