Tuesday 6 August 2019

Kotlin : Hello World Android App (Post 7)

Hi ,

After the basic of Kotlin App. Let's start android development with Kotlin language. In this post I am going to share the demo for simple hello world program with Kotlin language.

For setup of Kotlin Support , android studio will be required of 3.0 version and more.At the time of language selection , we need to select "kotlin" for programming language , when we create a new application.

When creating the android application with kotlin , we do not need to change the layouts , just src files will be changed.

Here I will just create one layout having textview in it ,and attach the activity with this textview . Let's have a look :

activity_main.xml :

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 
 xmlns:android="http://schemas.android.com/apk/res/android" 
 xmlns:tools="http://schemas.android.com/tools"
 xmlns:app="http://schemas.android.com/apk/res-auto"  
      android:layout_width="match_parent"  
      android:layout_height="match_parent" 
       tools:context=".MainActivity">

    <TextView    
      android:id="@+id/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>



MainActivity.kt:

package com.kotlindemo

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)
    }
}

Run the code:


That's it for this post , in next post I will discuss how TextViews and EditText is used in Kotlin.




No comments:

Post a Comment

Advanced Kotlin Coroutines : Introduction

 Hi,  Today I am unwraping the topic in Kotin world i.e. Coroutine . If you want to get started with Kotlin coroutine and ease your daily de...