官术网_书友最值得收藏!

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:

主站蜘蛛池模板: 苍南县| 多伦县| 健康| 巴彦县| 鲁甸县| 鄂托克旗| 翁源县| 龙泉市| 平昌县| 宣武区| 阳高县| 邵武市| 望谟县| 麦盖提县| 元谋县| 固安县| 庆元县| 陵川县| 婺源县| 枝江市| 贵港市| 嘉义县| 蓝田县| 三都| 兴海县| 孙吴县| 云霄县| 朝阳县| 肃北| 甘谷县| 阜平县| 兴文县| 六安市| 沁阳市| 铁岭县| 聂拉木县| 乐至县| 闵行区| 独山县| 黎川县| 黄梅县|