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

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:

主站蜘蛛池模板: 霍城县| 闽侯县| 敦煌市| 梅河口市| 阿坝| 漯河市| 固阳县| 浦北县| 奈曼旗| 芜湖市| 祁连县| 长宁区| 郸城县| 融水| 阿拉善左旗| 永善县| 清苑县| 武城县| 孟村| 阿尔山市| 汉沽区| 和林格尔县| 怀宁县| 弋阳县| 隆林| 绿春县| 惠来县| 宜城市| 通山县| 吉安市| 连云港市| 砀山县| 金华市| 怀仁县| 三江| 电白县| 博白县| 繁峙县| 井研县| 施甸县| 孟津县|