Build: WelcomeScreen
This screen shows a simple welcome message in the center of the screen.
Target UI
--------------------- | | | | | | | Welcome to my | | Android | | App! | | | | | | | ---------------------
--------------------- | | | | | | | Welcome to my | | Android | | App! | | | | | | | ---------------------
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 } }
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.
--------------------- | | | | | | | Welcome to my | | Android | | App! | | | | | | | ---------------------
MainActivity class in a simple Android app?MainActivity using Kotlin?MainActivity:
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
}
What will the user see when the app runs?MainActivity code snippet?
override fun onCreate(savedInstanceState: Bundle?) {
setContentView(R.layout.activity_main)
super.onCreate(savedInstanceState)
}Pass the test and this pattern moves unknown