0.布局文件
<?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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="45dp"
android:orientation="horizontal">
<TextView
android:id="@+id/tv"
android:text="用户名"
android:textSize="14sp"
android:gravity="center"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="45dp"/>
<EditText
android:id="@+id/username"
android:layout_width="0dp"
android:layout_weight="3"
android:layout_height="45dp" />
</LinearLayout>
</LinearLayout>
1.导入布局文件包,注入布局文件
import kotlinx.android.synthetic.main.activity_main.*
2.EditText赋值操作
username.text= Editable.Factory.getInstance().newEditable("G409")
3.TextView赋值
tv.text="用户"
4.创建一个方法设置返回数据类型为Int类型
fun sum(a: Int, b: Int): Int {
return a+b;
}