Android Calculator in Kotlin Using Android Studio

Hello Developer, In this tutorial, we will learn how to create an android calculator using Kotlin language in android studio full tutorial with code. using this code you can create your won calculator application in android studio using Kotlin language. This calculator app can perform basic arithmetic operations like multipication , addition, subtraction, or division.

Android Calculator in Kotlin

And if you want to know how to create an android calculator app using java programming language the read my previous article. This is a basic calculator app with limited functionality. follow our tutorial to make a simple calculator app in android studio using Kotlin language.

The buttons included should be:

  • Number Keys: “0”,”1″,”2″,”3″,”4″,”5″,”6″,”7″,”8″,”9″.
  • Operation Keys: “+”, “-”, “*”, “/”.
  • Other Keys: “=”, “CLEAR”.

For this calculator app we require some element.

  • Button
  • TextView

TextView : TextVIew we use to show user input number ,operations and also display the result.

Button : use to input value from 0 – 9 , input operations and some other use to calculate value and clear input.

Create a Calculator Android app using Kotlin language.

Step 1:

  • Open Your Android Studio. and then click on start a New Android Studio Project.
  • Under the Phone and Tablet tab, Select Empty Activity, and click Next button.
Android Calculator in Kotlin
  • Write your Project / Application Name “Calculator”  and select the language as Kotlin. leave other fields blank as it is, now click on the Finish Button your project will be loaded.

Step 2:

by default it will open to file MainActivity.kt and activity_main.xml .First, we are going to create user interface of calculator app using TextView, Button and Button.

  • Now, first open the activity_main.xml, from main layout file (res => layout => activity_main.xml ) this file contains the main layout of the android app, The layout code snippet is shown below. So, copy our xml codes from the below and add it to the  Activity_main.xml file in your project.

 Activity_main.xml

we have designed the User interface. now, we will add some code to the MainActivity.kt so that our app work like a real calculator.Now, open the MainActivity.kt file (src -> package -> MainActivity.kt) in MainActivity.kt, copy and paste the code of kotlin programming given below, which is the backend language.

MainActivity.kt

Congratulations! You have completed your basic calculator app using kotlin language. Now Run the app using the emulator

Our calculator app is running perfectly fine. Here some Screenshot.

This is how Basic Calculator app look like.

Android Calculator in Kotlin

Summary

So in this android tutorial, we have learned how to create a simple calculator app using kotlin language in android studio. if you are a beginner then this tutorial good for you. because this project will help you to improve your skill. if you like our tutorial then share this article with your good friends.

Leave a Reply

Your email address will not be published.