Kotlin系列课程——Kotlin初始化控件及界面跳转

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/android_gjw/article/details/78422307

Kotlin初始化控件是通过,导入kotlin自己的包,activity_main指向当前的的布局文件,必须要对应一致,才可以引用该布局中的控件

import kotlinx.android.synthetic.main.activity_main.*

这里写图片描述

导入相应的布局,就可以用该布局中的控件,直接用控件的id,kotlin会通过id,自动判断是哪种控件。
titletv是控件的id,然后是控件的监听

  titletv.setText("标题")
        titletv.setOnClickListener(View.OnClickListener {
            showToatWithShort("点击了")
        })

和布局id对应起来即可。

   <TextView
            android:id="@+id/titletv"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="14sp"
            android:textColor="@android:color/white"
            />

《Kotlin语法基础到实战开发》系列课程视频

http://edu.csdn.net/course/detail/6409?locationNum=7&fps=1&ref=srch&loc=1

http://edu.csdn.net/course/play/6409/123752

猜你喜欢

转载自blog.csdn.net/android_gjw/article/details/78422307