0
0
Android Kotlinmobile~20 mins

First Android app in Android Kotlin - Mini App: Build & Ship

Choose your learning style9 modes available
Build: WelcomeScreen
This screen shows a simple welcome message in the center of the screen.
Target UI
---------------------
|                   |
|                   |
|                   |
|   Welcome to my   |
|      Android      |
|       App!        |
|                   |
|                   |
|                   |
---------------------
Display a TextView with the text 'Welcome to my Android App!'
Center the text both vertically and horizontally
Use a simple white background
Starter Code
Android Kotlin
package com.example.firstapp

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity

class WelcomeScreen : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        // TODO: Set the content view with a layout containing the welcome text
    }
}
Task 1
Task 2
Task 3
Solution
Android Kotlin
package com.example.firstapp

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity

class WelcomeScreen : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_welcome_screen)
    }
}

/* XML layout file: res/layout/activity_welcome_screen.xml */

<?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"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#FFFFFF">

    <TextView
        android:id="@+id/welcomeText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Welcome to my Android App!"
        android:textSize="24sp"
        android:textColor="#000000"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

We created a simple activity WelcomeScreen that sets its content view to a layout file activity_welcome_screen.xml.

The layout uses ConstraintLayout to center a TextView both vertically and horizontally by constraining all sides to the parent.

The TextView displays the welcome message with a readable font size and black text on a white background.

This is the simplest way to create a centered welcome screen in Android using Kotlin.

Final Result
Completed Screen
---------------------
|                   |
|                   |
|                   |
|   Welcome to my   |
|      Android      |
|       App!        |
|                   |
|                   |
|                   |
---------------------
The screen shows the welcome message centered.
No buttons or interactions on this screen.
Stretch Goal
Add a button below the welcome text that shows a Toast message 'Button clicked!' when tapped.
💡 Hint
Add a Button widget below the TextView in the layout and set an OnClickListener in the activity to show a Toast.