Your first Android – Kotlin Project – Hello World !

Lets start kotlin coding with a much familiar and common project Hello World…!

For that , First start android studio version 3.0  Preview and follow these steps

Step 1:

Step 2:

Step 3 :

 

Step 4 :

 

Step 5:

Now click on Finish to create the new android-kotlin proect.

After that you will be landing on the android studio with an activity and its corresponding xml file ( Here it is Mainactivity.kt and activity_main.xml)

Now open MainActivity.kt and enter/paste the following code / check whether the codings are as follows :

package com.a4akhilsudha.myapplication

import android.support.v7.app.AppCompatActivity
import android.os.Bundle

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
    }
}

 

Now Update your activity_main.xml file as follows :

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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="com.a4akhilsudha.myapplication.MainActivity">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</android.support.constraint.ConstraintLayout>

And now run your first hello world project either using a real device or using a virtual device .

Congrats… ! Now you have created your first android – kotlin project.

Leave a Reply

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