介绍的话我就不说了,可以看我的第一篇关于Kotlin的文章,讲了为什么要用Kotlin的原因,进入正题,我们现在已经重新创建了一个Kotlin的项目,我在activity_main.xml文件中放了一个id为tv_hello的TextView和一个id为btn_test的Button,
然后在MainActivity.kt中的头部导入
贴一下布局文件activity_main.xml的的代码
<?xml version="1.0" encoding="utf-8"?><LinearLayout 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:orientation=“vertical”
android:gravity=“center”
android:layout_width=“match_parent”
android:layout_height=“match_parent”
tools:context=“.MainActivity”>
<TextView
android:id=“@+id/tv_hello”
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
android:tex