Skip to content
Related Articles

Related Articles

Improve Article

Hello Geeks! app in Kotlin

  • Last Updated : 17 Sep, 2019

We can build an android application using Kotlin and Java. In the tutorials, we are using Kotlin language to build the application. In previous tutorial, we learned how to create a project for Kotlin language but here, we will learn how to run an application using the AVD (Android Virtual Device).

We obtain two files when we launch the project, which are:

  • MainActivity.kt – This is Kotlin file and used to code in Kotlin language.
  • activity_main.xml – This is xml file and used for the layout of our main activity.

MainActivity.kt file

There are enormous number of activities in the Android application. For each of the activity we require a separate Kotlin file to write the code. All the functionalities are added like onclick, onCreate etc.

Kotlin code –




package com.geeksforgeeks.myfirstkotlinapp
  
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
  
class MainActivity : AppCompatActivity() {
  
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
    }
}

activity_main.xml file

For each activity there is separate xml file to specify the design or layout of our activities. Hence, there are number of functioning like we can adjust button to the top or bottom and make text bold or italic etc.

XML code –




<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
  
<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Hello Geeks!"
    android:textSize="50dp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintHorizontal_bias="0.496"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintVertical_bias="0.447" />
  
</androidx.constraintlayout.widget.ConstraintLayout>

Run as an Emulator

We made some changes in our Kotlin and xml files and then we can run our application using an emulator. It seems to be like below:-




My Personal Notes arrow_drop_up
Recommended Articles
Page :