DZone
Mobile Zone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
  • Refcardz
  • Trend Reports
  • Webinars
  • Zones
  • |
    • Agile
    • AI
    • Big Data
    • Cloud
    • Database
    • DevOps
    • Integration
    • IoT
    • Java
    • Microservices
    • Open Source
    • Performance
    • Security
    • Web Dev
DZone > Mobile Zone > Using Kotlin in Android Studio 3.0 (Part 1)

Using Kotlin in Android Studio 3.0 (Part 1)

This quick tutorial will show you how to get started developing mobile apps for Android with the Kotlin language.

Ngoc Minh Tran user avatar by
Ngoc Minh Tran
CORE ·
Mar. 07, 18 · Mobile Zone · Tutorial
Like (6)
Save
Tweet
11.01K Views

Join the DZone community and get the full member experience.

Join For Free

Background

When I wrote this article, I assumed that you already know about Android programming before. If you are Android beginners, you can read my other article, “Introduction Android programming using Android Studio 3.0.”

Why Is Kotlin?

  • Kotlin is very intuitive and easy to learn for Java developers
  • Android Studio 3.0 can understand, compile, and run Kotlin code easily

Installing the Android Studio 3.0 and Kotlin Plugin

  • We must download and install Android Studio 3.0 at  developer.android.com (current version is 3.0.1)
  • Checking Kotlin plugin installed by selecting File > Settings

Image title

Creating a New Android Application Using Kotlin

  • Creating a new project by selecting File > New > New Project. Enter a text for Application name and check out Include Kotlin Support checkbox as the following screenshot:

Image title

  • Click Next and Next and select Empty Activity. Click Next and Finish.
  • So far, we have activity_main.xml file (includes two modes: Design and Text) and MainActivity.kt file.
  • In right window, select app > res > values > strings.xml. Add a string element name hello_world to strings.xml file as follows:
<resources>
    <string name="app_name">My First Kotlin App</string>
    <string name="hello_world">Hello Kotlin</string>
</resources>
  • Select activity_main.xml file in Design mode. Select TextView and set a value (message) for ID and set a value (@string/hello_world) for text in Attributes window:

Image title

  • Select MainActivity.kt file and adding the import as follows:
import kotlinx.android.synthetic.main.activity_main.*
  • Add the following code line to the onCreate method:
message.text = "Hello My Kotlin App in Android Studio 3.0"


  • Do you remember the message? It is ID of TextView.
  • The complete code of MainActivity.kt, so far, can look like:
package com.example.admin.myfirstkotlinapp    
import android.support.v7.app.AppCompatActivity  
import android.os.Bundle  
import kotlinx.android.synthetic.main.activity_main.*  
class MainActivity : AppCompatActivity() {        
override fun onCreate(savedInstanceState: Bundle?) {          
     super.onCreate(savedInstanceState)          
     setContentView(R.layout.activity_main)          
     message.text = "Hello My Kotlin App in Android Studio 3.0"      
     }  }
  • Run App and the message "Hello My Kotlin App in Android Studio 3.0" will display.

Conclusion

In this article, I have only introduced how to install and create a simple Android application using Kotlin in Android Studio 3.0. In my next articles, I will introduce about more Kotlin language and how to create more complicate Android applications.

Android Studio Android (robot) Kotlin (programming language)

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Implementing Microservices Architectures
  • Kubernetes Service Types Explained In-Detail
  • SQL GROUP BY and Functional Dependencies: a Very Useful Feature
  • How to Translate Value to Executives Using an Outcome-Driven Mindset

Comments

Mobile Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • MVB Program
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends:

DZone.com is powered by 

AnswerHub logo