其他分享
首页 > 其他分享> > 组件

组件

作者:互联网

import android.widget.EditText
import android.widget.Button

//获取组件
var nianji_btn_btn = findViewById<Button>(R.id.nianji_btn);
var editText_txt = findViewById<EditText>(R.id.textView2);

//按钮点击事件
nianji_btn_btn.setOnClickListener {
            
}

//获取 输入框内容
 var txtData=editText_txt.getText().toString();

  

layout

   <EditText
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="176dp"
        android:layout_marginTop="74dp"
        android:layout_marginEnd="177dp"
        android:layout_marginBottom="177dp"
        android:text="TextView"
        android:lines="2"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/nianji_btn" />

 <Button
        android:id="@+id/nianji_btn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="158dp"
        android:layout_marginTop="23dp"
        android:layout_marginEnd="165dp"
        android:layout_marginBottom="270dp"
        android:text="二年级 "
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="1.0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/word_btn"
        app:layout_constraintVertical_bias="1.0" />

  

标签:findViewById,var,nianji,组件,import,btn,id
来源: https://www.cnblogs.com/dt1991/p/15352858.html