kotlin android studio tutorial with examples

Lesson1: Installing tools to program for Android with Kotlin

ContentsDownload tools needed to program for Android with Android Studio and Kotlin language Download tools needed to program for Android with Android Studio and Kotlin la…

Lesson2: Steps to Create the First Project in Android Studio with Kotlin

Once we start the Android Studio environment the main dialog appears: We chose the option “Start a New Android Studio project” Now a series of windows will ap…

Lesson 3 – Capture the click of a button in Kotlin

Make a program that allows the loading of two integers in controls of type EditText (Number). Display within the same EditText controls messages that request loading values. Have a Button to add the two values entered. Display the result in a TextView type control.

Lesson 4: RadioGroup and RadioButton Controls with example

The goal of this concept is to practice implementing a program that requires RadioButton type controls to select an activity. We will learn how to group a set of RadioButton and verify which one is selected.

Lesson 5: How to implement CheckBox Control and example

The objective of this concept is to continue practicing projects with Android Studio and incorporate the visual control CheckBox.

Create a project called Project004.

Lesson 6 – Control Spinner with examples

The goal of this concept is to continue practicing what has been seen until now and incorporate the Spinner visual control. The Spinner control displays a String list and allows us to select one of them. When it is selected it opens and shows all its elements to allow one to be selected.

Lesson 7: ListView Control (with a list of String) with examples

The ListView control, unlike the Spinner that closes after selecting an element, remains visible to several elements (used when displaying a list of similar elements).

In this first example, we will show a list of String (that is to say each element of the list is a String, we will see later that we can have lists of objects of another type: images, icons, several String by element, etc.)

Lesson 8 – Control ImageButton

We have seen the creation of objects of the Button class, now we will see another class very similar to the previous called ImageButton that has the same philosophy of handling with the difference that can show an image on its surface.

Lesson 9: Simple Notifications using the Toast class and example

Android allows you to display a temporary pop-up window that informs the user via a message that appears on the screen for a small amount of time (after a while the window disappears).

This window that overlays the interface that is being displayed at the moment is managed by a class called Toast.

Lesson 10 – Control EditText and example

From the first problem, we have been using the control that allows in Android to enter values by keyboard. The class that manages keyboard input is EditText.

But in the component palette we see that there are many types of EditText.

Lesson 11 – Launch a second “Activity” – example

It is very common for an application to have more than one window. To implement this in Android we must pose another two files one XML with the interface and another * .kt (Kotlin) with the logic (note that when we use Android Studio automatically when we create a project we create the XML file and the code in Kotlin of the first Activity)

Lesson 12: Launch a second “Activity” with Values (parameters)

We saw in the previous concept that a program can have more than one window representing each window with a class that inherits from AppCompatActivity.
A very common situation is that the first window needs to send data to the second so that from these proceed to perform an action.

Lesson 13 – Store Data Using the SharedPreferences Class

The Android platform gives us several facilities for permanent data storage (i.e they are not deleted when the application is shut down or closed)

Depending on the type of needs we will use one of these methods:

Lesson 14 – Storing data in a text file in the internal memory

Another possibility of storing data on our Android device is the use of a text file that will be stored in the internal storage of the computer (the other possibility is to store it on an SD Card)

Lesson: 15 – Store(Save) data in a text file on an SD card

In the previous concept, we saw how to create and read a text file in the internal memory of the Android team. In some situations, it might be useful to store the data on an SD card (keep in mind that not all Android devices have this feature) because of their increased capacity or the ease of sharing files with other people by delivering the SD card.

Lesson 16 – Store (save) data in SQLite database

So far we’ve seen two ways of permanently storing data (text files and the SharedPreferences class), now we’ll see another native Android tool for storing data in a database called SQLite.

SQLite is an Open Source database, it is very popular with many small devices like Android.

Lesson 17 – Installing Android App on a real device

Usually, one when developing applications on Android does all the programming, debugging and testing on a virtual device on the pc.
Now let’s see the steps to test the app on a real Android device.

The first way we will try to test our application is to copy the file with APK extension to our device.

Lesson 18 – Layout (LinearLayout) in Kotlin Example

Android organizes the visual components (Button, EditText, TextView etc.) on the screen using containers called Layout. So far we have not worried how to organize a screen, but we have focused on the functionality of each program we implement.

Lesson 19 – Layout (TableLayout) in Kotlin Example

The Layout of type TableLayout groups components into rows and columns. A TableLayout contains a set of TableRow-like components that group visual components for each row (each row can have a different amount of visual components)

Lesson 20 – Layout (FrameLayout) Example in Kotlin

The FrameLayout type control has all the visual controls aligned to the upper left vertex, centered, right lower vertex, and so on inside the container. (it has nine possible positions).
If we have two or more controls, they are stacked.

Lesson: 21 – Layout (ScrollView and LinearLayout) in Kotlin

The ScrollView along with a LinearLayout allows us to have a number of visual components that exceed the amount of space of the viewer of the phone or tablet. Then the user can move the created interface with his finger.

Lesson 22 – Application icon in Kotlin

When we create a project to implement an application with the Android Studio development environment, it creates two default icons:

Lesson 23 – Audio playback (file in raw folder) in Kotlin

We will see the steps to play an mp3 file (other formats supported by Android are: Ogg, Wav)

Lesson 24 – Play, Pause, Resume, and Stop an Audio file in kotlin

Create an application that allows you to start an mp3 file, stop, continue, permanently stop and activate or not playback in a circular way. Create an mp3 file with the Audacity program counting from 1 to 30 or upload your own mp3 file.

Lesson: 25 – Audio playback (file from SD card) in Kotlin

The purpose of this concept is to access an mp3 file stored on the SD card of our computer (keep in mind that this only works with a computer that has the capacity of SD card) We must use an emulator that has configured SD card, Meanwhile, you can use your mobile device.

Lesson 26 – Audio playback (file from internet) in Kotlin

Now let’s see the steps to play a file stored on an internet server.

27 – Playing audio using your own Android player (via Intent) in kotlin

Another way to run an mp3 file is through the built-in Android player. This application plays all formats supported by Android and has an interface that will be familiar to the user of our application.

Lesson 28: Record audio using Android recorder (via Intent) in Kotlin

The easiest way to capture audio on Android is through the recorder provided by the Android operating system. We invoke the recording application and then recover the recorded audio.

It has the advantage that the interface is familiar to the user, since many applications use this feature.

Lesson 29: Record audio using the MediaRecorder class in Kotlin

Another way to record audio on Android is to use the MediaRecorder class. This class gives us more freedom when it comes to building an application that requires audio recording.

Lesson 30 – Draw: graphing pixels in kotlin

Graph 10000 pixels in a random white color on the device screen with black background. In order to do this simple task, we must follow a series of steps…

Lesson 31 – Draw: draw background and draw lines in Kotlin

Paint the yellow background and draw a series of lines with different styles.

1 – We created a project called: Project034

Lesson 32 – Draw: rectangles in Kotlin

Paint the white background and draw a series of rectangles with different styles.

Lesson 33 – Draw: circles in kotlin

Paint the white background and draw 10 circles growing from the middle of the screen.

lesson 34 – Draw: ovals in Kotlin

Lesson 35 – Draw: text in kotlin

Another resource that allows the Canvas class is to plot text. We delete the TextView that automatically adds the Android Studio and define the ConstraintLayout id with the value: layout1…

36 – Draw: text with external font style in kotlin

We can build applications and incorporate external True Type fonts. For this, we will implement an application that shows a text with an external source.

Lesson 37 – Draw: text on a path in kotlin

If we want to have text that is not horizontal, we must create a path indicating the points where the text will pass.

Lesson 38 – Draw: an image in kotlin

To display a jpg file, png etc. We have in the Canvas class a method called drawBitmap. Display the contents of a jpg file on the screen knowing it has a size of 250 pixels wide by 200 high.

Lesson 39 – Touch event: draw a circle in kotlin

A fundamental activity is to be able to detect when the user selects or touches the touch screen. Develop a program that draws a circle in the 100,100 coordinate. When another part of the touch screen is pressed, move the circle to that coordinate.