Make Your 1st Android App using Kotlin - Android Studio

10 April, 2020

In this tutorial you will learn Step by Step process for making an Android Mobile App. We will create Android App in the Android Studio using Kotlin Programming Language.

Android App using Kotlin

This is a very basic learning tutorial especially for the android beginners.


In this tutorial you will learn the following: ★ Creating Android Studio Project, ★ Simple Text View, ★ Button View ★ Button on Click Listener and ★ Creating New Activity and ★ Image View ★ Run App in the Emulator and ★ Build Android APK file.

Table of contents:
  1. Create New Project
  2. Create Empty Activity
  3. Add an Image
  4. Add xml Codes
  5. Add Kotlin Codes
  6. Run App

▶ Step by Step process Installing Android Studio.
Web Link: https://jonyapps.com/installing-android-studio/

1. Create A New Android Studio Project:

At first, click on the Android Studio Icon to open the Android Studio Project. Click on the “Start a new Android Studio project”, Select Empty Activity and press Next Button to create new project. Don’t forget to select language as “Kotlin”.




2. Create an Empty Activity:

We will create an Empty Activity now. When Button will be clicked a new activity will open. Follow below images to create an Empty Activity. Click on the image for ZoomView.



3. Add an Image:

We need to add an Image because in this tutorial we will also show an ImageView. When button will be clicked an Activity will open and Image will be shown.

You can add below Sample Image into your project. Click on below Image and Download into your computer.






4. Add xml Codes:

Copy and Paste below codes to your activitymain.xml and activitymain2.xml files

activity_main.xml

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

   <TextView
       android:id="@+id/textView1"
       android:layout_marginTop="100dp"
       android:layout_centerHorizontal="true"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:text="This is My Android App"
       android:textSize="20sp"
       android:textStyle="bold"/>

   <TextView
       android:id="@+id/textView2"
       android:layout_below="@+id/textView1"
       android:layout_marginTop="30dp"
       android:layout_centerHorizontal="true"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:text="Welcome to My First App"
       android:textSize="16sp"
       android:textStyle="bold"
       android:textColor="@color/colorPrimary"/>

   <Button
       android:id="@+id/button"
       android:layout_below="@+id/textView2"
       android:layout_marginTop="50dp"
       android:layout_centerHorizontal="true"
       android:layout_width="200dp"
       android:layout_height="wrap_content"
       android:text="Go Next" />
</RelativeLayout>

activity_main2.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 
   xmlns:android="http://schemas.android.com/apk/res/android"
   xmlns:tools="http://schemas.android.com/tools"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   tools:context=".Main2Activity">

   <TextView
       android:id="@+id/text1"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:text="This is an ImageView"
       android:textSize="25sp"
       android:layout_marginTop="50dp"
       android:layout_centerHorizontal="true"/>

   <ImageView
       android:layout_width="match_parent"
       android:layout_below="@+id/text1"
       android:layout_height="wrap_content"
       android:src="@drawable/image_a"/>
</RelativeLayout>

5. Add Kotlin Codes:

Now I will add very simple code to the MainActivity.Kt file. This code will be responsible for Button click. Copy below codes and paste into the MainActivity.Kt file.


MainActivity.Kt
package com.jonyapps.myfirstapp

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import kotlinx.android.synthetic.main.activity_main.*

class MainActivity : AppCompatActivity() {

   override fun onCreate(savedInstanceState: Bundle?) {
       super.onCreate(savedInstanceState)
       setContentView(R.layout.activity_main)
       button.setOnClickListener {
           val intent = Intent (this, Main2Activity::class.java)
           startActivity(intent)
       }
   }
}

6. Run the App:

Now Everything is Done! Fllow below images to run the App with Emulator.



If you have any comments please post below.


Read Our Posts

*Install Our Apps from Google Play Store
->Installing Android Studio
->Installing JDK on Windows
->Make Your 1st Android App
->Custom Toast Message
->Android Snackbar
->Android Alert Dialog
->Android Custom ListView
->RecyclerView with CardView
->Android Notifications
->Android Splash Screen
->Convert Website into App
->Custom Buttons
->Custom TextView
->ProgressBar- Glide/Picasso
->Implement app-ads.txt