Table of contents
No headings in the article.
In this blog, we will be creating a basic "Hello Android App" Using Kotlin:
A Step-by-Step Guide -
Introduction: Kotlin is a modern and concise programming language that has gained popularity for Android app development. Are you a beginner and scared of making projects? This blog provides step-by-step instructions so a beginner can easily make their first project.๐ป
Step 1: Setting up the Development Environment To begin, ensure that you have the following set up on your machine:
Android Studio (latest version)
JDK (Java Development Kit)
Step 2: To create a New Project:
Open Android Studio and select "File>New>New Project".
You will see some templates for your app. Choose "Empty Activity" as the template for your new project.
Enter the project name (Hello Android in this case) and you will see that the package name for your project will be created below.
Choose the project location and click "Finish" to create the project.
(You can add Kotlin support to your project too)
Step 3: Modifying the Layout
Open the activity_main.xml file located in the res/layout folder.
You need to replace the existing code with the following:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:orientation="vertical"
tools:context=".MainActivity">
<TextView
android:id="@+id/helloTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello Android!"
android:textSize="24sp"
android:layout_gravity="center_horizontal"/>
</LinearLayout>
Step 4: Write the Kotlin Code
Open the MainActivity.kt file located in the app/src/main/java/package_name folder.
Replace the existing code with the following:
package com.example.yourpackage
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)
val helloTextView = findViewById<TextView>(R.id.helloTextView)
helloTextView.text = "Hello Android!"
}
}
Step 5: Running the App
Connect your Android device or start an emulator.
Click on the "Run" button (the green triangle) in Android Studio's toolbar.
Select your device/emulator from the list.
You need to wait for the app to build.
Once installed, the app will display "Hello Android!" on the screen.
Conclusion: Congratulations!๐ You have successfully created a basic Hello Android app using Kotlin. You learned how to set up the development environment, create a new project, add Kotlin support, modify the layout, and write the Kotlin code. This is just the beginning of your journey into Android app development with Kotlin. Happy coding!
Happy Coding!!