How to Create and Save a Kotlin File in Android Studio
In the first post, we talked about what Kotlin is and why we use it for Android development. Now, let’s take the next step: creating and saving Kotlin files in Android Studio.
If you’re just starting out, don’t worry — this guide is beginner-friendly!
🗂 What Is a .kt File?
Kotlin files use the .kt extension, which stands for Kotlin.
For example:
MainActivity.kt
MyUtils.kt
LoginScreen.kt
This file contains Kotlin code — classes, functions, variables — that define what your app does.
📁 How to Create a Kotlin File in Android Studio
Here are the steps to create a Kotlin file (or class) inside your Android project:
✅ Method 1: Create a Kotlin Class/File
-
Open Android Studio and make sure your project is loaded.
-
In the Project pane, right-click on the folder where you want to add the file — usually:
Select: New > Kotlin Class/File
Enter the name of your file (e.g.,
MainActivity)Choose the type:
Class– for creating a classFile– for writing functions outside of classesInterface,Enum, etc. – depending on what you needClick OK, and Android Studio will create a file like: MainActivity.kt
Pro Tip: Where Should You Save Kotlin Files?
In Android Studio projects, Kotlin files are usually saved under:
app > src > main > java > com.yourapp.name
Σχόλια
Δημοσίευση σχολίου