- Android Development with Kotlin
- Marcin Moskala Igor Wojda
- 177字
- 2021-07-02 18:48:32
Using Kotlin in a new Android project
For new Kotlin projects created in Android Studio 3.x, the main activity will be already defined in Kotlin, so that we can start writing Kotlin code right away:

Adding a new Kotlin file is similar to adding a Java file. Simply right-click on a package and select new | Kotlin File/Class:

The reason why the IDE says Kotlin File/Class and not simply Kotlin class, which is analogous to Java class, is that we can have more members defined inside a single file. We will discuss this in more detail in Chapter 2, Laying a Foundation.
Notice that Kotlin source files can be located inside the java source folder. We can create a new source folder for Kotlin, but it is not required:

Running and debugging a project is exactly the same as in Java and does not require any additional steps besides configuring Kotlin in the project:

Starting from Android Studio 3.0, various Android templates will also allow us to select a language. This is the new Configure Activity wizard:

推薦閱讀
- Java程序設計與開發
- Objective-C Memory Management Essentials
- 大學計算機應用基礎實踐教程
- Building a Game with Unity and Blender
- Visual FoxPro 程序設計
- Django:Web Development with Python
- Bootstrap 4:Responsive Web Design
- Learn React with TypeScript 3
- H5頁面設計:Mugeda版(微課版)
- 響應式架構:消息模式Actor實現與Scala、Akka應用集成
- 持續輕量級Java EE開發:編寫可測試的代碼
- C#程序設計(項目教學版)
- Arduino Wearable Projects
- 深入解析Java編譯器:源碼剖析與實例詳解
- Appcelerator Titanium:Patterns and Best Practices