3.Create “Hello World” application. That will display “Hello World” in the middle of the screen in the red color with white background. ACTIVITY_MAIN.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" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity"> <TextView android:id="@+id/textview" android:layout_width="303dp" android:layout_height="66dp" android:ems="10" android:inputType="textPersonName" android:text="MAD LAB” android:textColor=”#289428” android:textAllCaps=”true” android:textSize=”20dp” app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent"/> </androidx.constraintlayout.widget.ConstraintLayout> MAINACTIVITY.kt package com.example.helloworld import androidx.appcompat.app.AppCompatActivity import android.os.Bundle //Bundle is a class in android studio used to transfer data from one UI component activity to another UI component activity to another UI component activity. import android.widget.Toast class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { //Bundle defines 2 methods onFreeze() and onCreate() onFreeze() assigns value to UI component in design phase and onCreate() takes parameter of component during runtime super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) //R is a resource set in activity_main.xml and used in kt file with resource id } }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter