Introduction
Welcome to your first Android application! In this tutorial, we’ll walk through creating a simple “Hello World” app in Android Studio. This is the foundation for all Android development and will introduce you to the basic structure of an Android project.
Prerequisites
Before starting this tutorial, make sure you have:
- Android Studio installed (see Android Studio Setup)
- A virtual device (AVD) or physical Android device ready for testing
- Basic understanding of Java or Kotlin programming
Video Tutorial
Follow along with this step-by-step video guide:
infoWatch the video for a complete walkthrough, then use the written instructions below as a reference!
Creating a New Project
Launch Android Studio
- Open Android Studio
- From the welcome screen, click New Project
- If you already have a project open, go to File → New → New Project
Select Project Template
- In the “New Project” window, select Empty Views Activity
- Click Next
infoThe Empty Views Activity template provides a basic activity with an XML layout and minimal code, perfect for learning. Note: the template named Empty Activity now creates a Kotlin/Jetpack Compose project instead.
Configure Your Project
Fill in the following details:
- Name: HelloWorld
- Package name: com.example.helloworld
- Save location: Choose your preferred directory
- Language: Java or Kotlin (your choice)
- Minimum SDK: API 21 (Android 5.0)
Click Finish when done.
Wait for Gradle Build
Android Studio will now:
- Create your project structure
- Download necessary dependencies
- Build your project
This may take a few minutes on first run.
Understanding the Project Structure
Key Files and Folders
Project Components
- app/src/main/java/ - Contains your Java/Kotlin code
- app/src/main/res/ - Contains all resources (layouts, images, strings)
- app/src/main/AndroidManifest.xml - App configuration and permissions
- build.gradle - Build configuration files
MainActivity
// Java version
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
// Kotlin version
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
}
}
Layout XML
<?xml version="1.0" encoding="utf-8"?>
<!-- activity_main.xml -->
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
android:textSize="24sp" />
</androidx.constraintlayout.widget.ConstraintLayout>
Running Your App
Select Your Device
- Click the device dropdown in the toolbar
- Select your virtual device or connected physical device
Run the Application
- Click the Run button (green play icon) or press Shift + F10 (Windows/Linux) or Ctrl + R (macOS)
- Wait for the app to build and deploy
- The app will launch on your selected device
View the Result
You should see “Hello World!” displayed on the screen!
Customizing Your Hello World App
Changing the Text
Open the Layout File
- In the Project window, navigate to app/src/main/res/layout/
- Double-click activity_main.xml to open it
- At the top-right of the editor, switch to Code view (or Split view to see the code and design preview side by side)
Edit the TextView Directly
Find the TextView element and change the value of the android:text attribute:
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello, Android Development!"
android:textSize="24sp" />
Re-run the app to see your new text on the screen.
errorHardcoding text directly in the layout works, but Android Studio will show a lint warning. The recommended approach is to use a string resource — see the next step.
Use a String Resource (Recommended)
- Open app/src/main/res/values/strings.xml
- Add a new string entry:
<resources>
<string name="app_name">HelloWorld</string>
<string name="greeting">Hello, Android Development!</string>
</resources>
- Back in activity_main.xml, reference the resource instead of hardcoding the text:
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/greeting"
android:textSize="24sp" />
- Run the app again — the text comes from your string resource
infoKeeping all user-facing text in strings.xml makes your app easier to maintain and is required for supporting multiple languages later.
Adding Colors
Define Colors in colors.xml
- In the Project window, navigate to app/src/main/res/values/
- Open colors.xml (create it via right-click → New → Values Resource File if it doesn’t exist)
- Add your custom colors as hex values:
<resources>
<color name="my_text_color">#1565C0</color>
<color name="my_background_color">#FFF9C4</color>
</resources>
infoColors use hex format: #RRGGBB, or #AARRGGBB if you want transparency (alpha). Android Studio shows a color swatch in the editor gutter — click it to open a color picker.
Apply Colors in the Layout
Open activity_main.xml and use android:textColor on the TextView and android:background on the root layout:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/my_background_color">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/greeting"
android:textColor="@color/my_text_color"
android:textSize="24sp" />
</androidx.constraintlayout.widget.ConstraintLayout>
Run and Verify
- Run the app again (Shift + F10 on Windows/Linux, Ctrl + R on macOS)
- You should see your custom text in your chosen color on the new background color
infoJust like strings, defining colors in colors.xml instead of hardcoding hex values in layouts keeps your theme consistent and easy to change in one place.
Common Issues and Solutions
-
Build fails with “SDK not found” chevron_right
Make sure you have installed the Android SDK through the SDK Manager. Go to Tools → SDK Manager and ensure the latest SDK is installed.
-
App crashes immediately on launch chevron_right
Check the Logcat window for error messages. Common causes include:
- Incorrect minimum SDK version
- Missing permissions in AndroidManifest.xml
- Syntax errors in layout XML
-
Emulator won’t start chevron_right
Refer to the Android Studio Setup troubleshooting section for emulator issues.
Next Steps
After completing your first Hello World app, you can:
- Modify the UI - Change colors, fonts, and layouts
- Add user interaction - Implement buttons and click listeners
- Learn about Activities - Understand the Android lifecycle
- Explore Views and Layouts - Build more complex interfaces
- Add tests - Add tests for your code
Additional Resources
infoPractice by creating variations of this app - try different text, colors, and layouts to get comfortable with Android Studio!