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

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:

主站蜘蛛池模板: 牡丹江市| 福州市| 望江县| 南靖县| 湟源县| 凤城市| 武穴市| 雅江县| 偏关县| 锡林浩特市| 迁安市| 石屏县| 明星| 松江区| 铅山县| 沧州市| 沧州市| 通州区| 金堂县| 高要市| 抚州市| 东台市| 彭山县| 手机| 安新县| 太仆寺旗| 福海县| 出国| 米林县| 馆陶县| 遂溪县| 旺苍县| 台山市| 江北区| 阳东县| 西乌珠穆沁旗| 明水县| 徐闻县| 满城县| 金山区| 青岛市|