android studio 创建Activity
新建时,最下面的Source Language选择Kotlin.
创建activity
创建完成后,AndroidStudio会自动帮我们生成以Kotlin方式创建的Activity。
package com.example.ado.myapplication
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
class KotlinActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_kotlin)
}
}
对应布局 activity_kotlin.xml
定义了一个TextView。
<android.support.constraint.ConstraintLayout
xmlns:android=“http://schemas.android.com/apk/res/android”
xmlns:app=“http://schemas.android.com/apk/res-auto”
xmlns:tools=“http://schemas.android.com/tools”
android:layout_width=“match_parent”
android:layout_hei