In this tutorial, I’ll show you how to build your first Android app in this tutorial. In the process, I’ll introduce you to fundamental Android concepts like views, layouts, and activities.
Prerequisites
You’ll need the following to follow along:
- Android Studio (latest version)
- Android Marshmallow or higher on a device or emulator
Step 1: Create a New Project in Android Studio
- Open Android Studio – > Select File Option – >New -> New Project
- Select Empty Activity
- Give your Application name such as First Android App
- Make sure that the language is set to Kotlin
- I recommended Kotlin For Beginners
- Click on finish
File : MainActivity.kt
–>By default the MainActivity.kt is looked like a sample image is given below.
![MainActivity](https://developersdome.comwp-content/uploads/2021/07/First-Android-App-Blog-post-–-MainActivity.kt-First_Android_App_Blog_post.app-13-07-2021-11_25_49-1024x549.png)
File: MainActivity.kt
–>By default MainActivity.kt file contains onCreate() function.
package com.sagar.firstandroidappblogpost 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) } }
File: activity_main.xml
–> By default the activity_main.xml is looked like a sample image is given below.
![activity_main](https://developersdome.comwp-content/uploads/2021/07/First-Android-App-Blog-post-–-MainActivity.kt-First_Android_App_Blog_post.app-13-07-2021-11_36_07-1024x549.png)
File: activity_main.xml
–> By default activity_main.xml file contain textView placed inside a ConstraintLayout.
<?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.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" android:background="@color/black" tools:context=".MainActivity"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Your First Android App" android:textColor="@color/white" android:textSize="35sp" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toTopOf="parent" /> </androidx.constraintlayout.widget.ConstraintLayout>
Preview
Conclusion
You’ve just finished your first Android app that’s totally working! I recommend that you make a few changes. You could experiment with the button positions and the clock view.
- We hope that this guide will assist you in quickly build your First Android App in kotlin. If you have any problems, please post them in the comments section and we will gladly assist you.
Pingback: What is Android Studio | Utilities in Android Studio 2021