How to Create a Simple Android App Using Android Studio.

Creating an Android app is easier than you might think. Whether you’re a beginner or an experienced developer, Android Studio provides all the tools you need to build an app from scratch. In this blog post, I’ll guide you step by step on how to create a simple Android app that displays a welcome message when a button is clicked.

Step 1: Install and Set Up Android Studio

Before we begin coding, make sure you have Android Studio installed on your computer.

How to Install Android Studio:

  1. Download Android Studio from the official website: developer.android.com/studio
  2. Run the installer and follow the on-screen instructions.
  3. Open Android Studio and select “New Project”.

Step 2: Create a New Android Project

  1. Select “Empty Activity” as the project template.
  2. Enter the following details:
    • App Name: SimpleApp
    • Package Name: com.example.simpleapp
    • Language: Java
    • Minimum SDK: API 21 (Android 5.0 Lollipop)
  3. Click Finish and wait for the project to set up.

Step 3: Design the User Interface (UI)

Android Studio uses XML files to define the layout of an app. Let’s create a simple interface with a TextView and a Button.

Modify activity_main.xml

  1. Open res/layout/activity_main.xml.
  2. Replace the default code with this:

What This Code Does:

  • Creates a TextView that will display messages.
  • Adds a Button that will trigger an action when clicked.

Step 4: Write the Java Code

Now, let’s make the button functional using Java.

Modify MainActivity.java

  1. Open MainActivity.java in app/src/main/java/com/example/simpleapp/.
  2. Replace the existing code with this:

What This Code Does:

  • Finds the TextView and Button by their IDs.
  • Sets up an onClickListener to change the text when the button is clicked.

Step 5: Run the App

  1. Click the Run ▶ button in Android Studio.
  2. Choose an emulator or connect a real Android device.
  3. Wait for the app to launch, then click the button.
  4. The text should change to “Welcome to Your First Android App!”

Leave a Reply

Your email address will not be published. Required fields are marked *

More Articles & Posts