Before you start
By the end you can
- create a layout and an activity class, and declare it as the screen the icon opens;
- run the app on the emulator and use its controls;
- change the app’s theme.
- Android Studio Project
- Layout Code
- Java
- Manifest
- Emulator
Behind, or a fresh project? Start from here about 3 min
The project: your own from Part 1, or a fresh one: Part 0, steps 0.3 and 0.4 (about 5 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.
Gradle: check these 3 lines. Add any that is missing, then click Sync Now. Keep your own version numbers.
Gradle Scripts › libs.versions.tomlAdd the marked lines[versions]agp = "9.5.0"junit = "4.13.2"junitVersion = "1.3.0"espressoCore = "3.7.0"appcompat = "1.8.0"material = "1.14.0"constraintlayout = "2.2.2"
[libraries]junit = { group = "junit", name = "junit", version.ref = "junit" }ext-junit = { group = "androidx.test.ext", name = "junit", version.ref = "junitVersion" }espresso-core = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "espressoCore" }appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "appcompat" }material = { group = "com.google.android.material", name = "material", version.ref = "material" }constraintlayout = { group = "androidx.constraintlayout", name = "constraintlayout", version.ref = "constraintlayout" }
[plugins]android-application = { id = "com.android.application", version.ref = "agp" }Gradle Scripts › build.gradle.kts (Module :app)Add the marked linesplugins { alias(libs.plugins.android.application)}
android { namespace = "com.yourname.notes" compileSdk { version = release(37) }
defaultConfig { applicationId = "com.yourname.notes" minSdk = 24 targetSdk = 37 versionCode = 1 versionName = "1.0"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" }
buildTypes { release { optimization { enable = true packageScope = setOf("androidx.**", "kotlin.**", "kotlinx.**") } } } compileOptions { sourceCompatibility = JavaVersion.VERSION_11 targetCompatibility = JavaVersion.VERSION_11 }}
dependencies { implementation(libs.appcompat) implementation(libs.material) implementation(libs.constraintlayout) testImplementation(libs.junit) androidTestImplementation(libs.espresso.core) androidTestImplementation(libs.ext.junit)}▶. You are ready when the red balloon says Default Activity not found.
Step 1 of 5
Create the layout
Goal Create activity_main.xml, the file that says what your screen shows: “Hello, Notes!” in the middle.
- Android Studio Project
- Layout res › layout › activity_main.xml
-
A new resource file, from the menu of res.
- In the Project window, right-click res, under app.
- A menu opens: choose NewAndroid Resource File.
Project › res A menuFull size
- Right-click res › New.
- Android Resource File: the layout.
-
Its name and its type:
activity_main, a layout.- A New Resource File window opens. In File name, type
activity_main. - In Resource type, open the list, then choose Layout.
- Root element shows
androidx.constraintlayout.: keep it.widget. ConstraintLayout - Leave Source set and Directory name as they are, then click OK.
New Resource File A dialogFull size
- File name:
activity_main. - Resource type: Layout, in the list.
- Root element:
androidx.constraintlayout..widget. ConstraintLayout
- A New Resource File window opens. In File name, type
-
Paste The screen: “Hello, Notes!” in the middle.
- The file opens in Design. Click Code, at the top right of the editor.
- Click Copy the file, at the top right of the panel below.
- In Code, click in the text, press Ctrl+A, then Ctrl+V.
res › layout › activity_main.xmlReplace the whole file<?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">
<TextView android:id="@+id/textHello" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Hello, Notes!" android:textSize="24sp" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>Part 3 explains these lines. For now, notice line 7. Since Android 15, an app draws under the status bar and the navigation bar:
android:fitsSystemWindows="true"keeps your screen out from under them. -
The preview, beside the code.
- Click Split, at the top right of the editor: the preview shows beside the code.
Done I see “Hello, Notes!” in the preview.
Stuck? 2 symptoms · the file
ConstraintLayoutis red, and the preview shows an error Android Studio is still syncing or indexing: wait for the bar at the bottom of the window to end. Still red? A letter of the tag differs: paste the file again.- No preview beside the code Click Split, at the top right of the editor. Code shows the XML alone.
The file at the end of this step is the panel above: Copy the file.
Step 2 of 5
Write the activity class
Goal Create MainActivity, the Java class Android runs for this screen, and make it show your layout.
- Android Studio Project
- Java kotlin+java › com.yourname.notes › MainActivity.java
-
A new Java class, in the plain package.
- In Project, open kotlin+java: it holds three com.yourname.notes.
- Right-click the first, the plain com.yourname.notes, without
(test)or(androidTest). - A menu opens: choose NewJava Class, at the top of the submenu.
Project › kotlin+java A menuFull size
- The plain
com.yourname.notes, the first one: right-click it. - New.
- Java Class.
-
Its name:
MainActivity.- A small New Java Class popup opens: type
MainActivity. - Keep Class selected below, then press Enter:
MainActivity.javaopens.
New Java Class A dialogFull size
- New Java Class: type
MainActivity. - Class: keep it, then press Enter.
- A small New Java Class popup opens: type
-
Type The class: it extends
AppCompatActivityand shows your layout.- On the line
public class MainActivity {, click right afterMainActivity, then type a space andextends AppCompatActivity. - A completion list has opened: press Esc. Enter would pick an item.
- Click right after the class line’s
{, then press Enter twice: one empty line stays under it. - Type
@Override: a list opens. Press Esc, then Enter. - Type the
onCreateline up to its{: Android Studio adds the}. Press Enter. - Above that
}, type the panel’s lines 11 and 12.
kotlin+java › com.yourname.notes › MainActivity.javaNew filepackage com.yourname.notes;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); }}Grey lines: Android Studio writes them, with the class and with Alt+Enter.
- On the line
-
The two imports, lines 3 and 5.
- Click the red
AppCompatActivity, then press Alt+Enter. - A menu opens: choose Import class. The panel’s line 5 appears at the top.
- Do the same on the red
Bundle: the panel’s line 3,android.os.Bundle, appears.
- Click the red
Why A recipe, for now: Android calls onCreate() when the screen opens, and setContentView() shows your layout. Part 5 explains both.

- The path:
app › src › main › java, the right folder.
Done I see nothing red, and app › src › main › java in the path at the bottom of the window.
Stuck? 4 symptoms · the file
MainActivitysits under(test)or(androidTest)It is in a test folder. Drag it onto the plain com.yourname.notes, as in the capture below.- No plain
com.yourname.notesunder kotlin+java Right-click kotlin+java › NewPackage, click OK (…\app\src\main\javais already selected), then type your package and press Enter. - Alt+Enter offers nothing Android Studio is still indexing: the bar at the bottom of the window. Wait for it to end.
- Still red Replace the whole file with this one. The Copy the file button writes your package on its first line.

MainActivity, inside the plaincom.yourname.notes.(androidTest)and(test): tests, not here.
The files at the end of this step
package com.yourname.notes;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); }}Step 3 of 5
Declare the screen in the manifest
Goal Add MainActivity to the manifest, as the screen the app’s icon opens.
- Manifest manifests › AndroidManifest.xml
-
Paste The manifest, with
MainActivityas the screen the icon opens.- In Project, open manifests, then double-click AndroidManifest.xml.
- Click Copy the file, at the top right of the panel below.
- In the editor, click in the text, press Ctrl+A, then Ctrl+V.
manifests › AndroidManifest.xmlReplace the whole file<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools">
<application android:allowBackup="true" android:dataExtractionRules="@xml/data_extraction_rules" android:fullBackupContent="@xml/backup_rules" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/Theme.Notes"> <activity android:name=".MainActivity" android:exported="true"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application>
</manifest>
Why MAIN and LAUNCHER say “this one gets the icon”, as chapter 02 showed. exported="true": another app, here the launcher, may open it.
Stuck? 1 symptom · the file
android:exported needs to be explicitly specified for element <activity#…MainActivity>Theexportedline was lost. Paste the manifest again.
The file at the end of this step is the panel above: Copy the file.
Step 4 of 5
Run it on the emulator
Goal Build, install and open your app on the virtual phone, then use the phone’s controls.
- Android Studio ▶ Run 'app'
- Emulator Running Devices
-
Your app, built, installed and opened on the phone.
- In the toolbar, top right, the device menu must read Pixel 7. If not, open it and choose Pixel 7.
- Click the green ▶ Run 'app', right of the app menu (Shift+F10).
- Wait about a minute for the first build: Running Devices then shows your app, in its tab Pixel 7 API 37.0.
Toolbar and Running Devices Toolbar · topFull size
- The device menu: Pixel 7.
- ▶ Run 'app'. Once the app runs, it becomes ↻ Rerun, next to the red ■ (stop).
- Back, Home, Overview: the phone’s three buttons. Overview shows the recent apps (chapter 03’s Recents).
- Rotate Left, Rotate Right: turn the phone.
-
The phone’s home screen.
- In the toolbar of Running Devices, click Home.
-
The app list, then your app.
- On the phone’s screen, drag up from the middle: the app list opens.
- Click Notes (a click is a tap): your app opens.
- Gradle builds the app into an APK, the file Android installs
- Android Studio installs it on the phone
- Android opens the activity marked
LAUNCHER

You should see “Hello, Notes!” under a purple bar titled “Notes”, below a purple status bar with white icons.
Done I see Notes in the phone’s app list.
Stuck? 3 symptoms
- “Waiting for all target devices to come online” The phone is still booting: wait.
Default Activity not foundagain The manifest was not replaced. Do step 2.3 again.- The build succeeds, but the app closes at launch
MainActivitysits in(test)or(androidTest). Drag it onto the plain package. error: package R does not existThe first line ofMainActivityis not your package. Copy the class from step 2.2’s Stuck?
No file changes in this step: steps 2.1 to 2.3 hold the three files.
Step 5 of 5
Remove the bar with a theme
Goal Give the app a theme without the purple action bar, and with dark status icons.
- Resources res › values › themes.xml
- Emulator
-
The theme without its night copy: that copy keeps the old bar.
- In Project, open res › values › themes: it holds themes.xml and themes.xml (night).
- Right-click themes.xml (night), then choose Delete… in its menu.
- A Delete window opens,
Delete file "themes.xml"?: leave both boxes ticked, then click OK.
Delete A dialogFull size
- Delete: the dialog’s title.
- OK: leave both boxes ticked.
-
Paste The theme, without the action bar.
- In res › values, double-click themes.xml, now alone.
- Click Copy the file, at the top right of the panel below.
- In the editor, click in the text, press Ctrl+A, then Ctrl+V.
res › values › themes.xmlReplace the whole file<resources> <style name="Theme.Notes" parent="Theme.Material3.Light.NoActionBar"> <item name="android:windowLightStatusBar">true</item> </style></resources>A theme sets the look of the whole app: its colours and its bars. Your notes screen draws its own header in Part 3, so the template’s bar goes:
NoActionBar.windowLightStatusBar: dark status icons, for the light background behind them. -
Your app again, with its new theme.
- In the toolbar, click ↻ Rerun, where ▶ Run 'app' was. Your app has stopped? Click ▶ Run 'app'.

You should see No bar. The status bar icons are dark on the light background:

Done I see no bar, and dark icons at the top.
Stuck? 1 symptom · the file
- Still a purple bar titled “Notes”
themes.xmlwas not replaced. Paste it again, then click ↻ Rerun.
The file at the end of this step is the panel above. values-night/themes.xml is deleted.
Now you
Hello, your name
Make the screen say “Hello, your name!”. Which file do you change?
See the answer
res/layout/activity_main.xml, line 14: the android:text attribute. Then click ↻ Rerun. Keep your name: Part 3 deletes this text.
If it doesn’t work
- “Waiting for all target devices to come online” The phone is still booting: wait.
error: cannot find symbol … symbol: method enableEdgeToEdge(Window)A tutorial’s line,WindowCompat.enableEdgeToEdge(…), is inMainActivity. Remove it. This lab needs no edge-to-edge line,EdgeToEdge.enable(this)included.
End of the part
Recap
Three files make a screen. The layout says what it shows, the class shows it with setContentView(), and the manifest lets Android open it. No more Default Activity not found.
- create a layout and an activity class, and declare it as the screen the icon opens;
- run the app on the emulator and use its controls;
- change the app’s theme.

