特殊的按钮组件
ToggleButton切换按钮
ToggleButton 是一种特殊的按钮,里面可以定义两种选项,当你点击时便会切换这两种选项。定义方式如下:
<ToggleButton
android:id="@+id/toggleButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="144dp"
android:layout_marginLeft="144dp"
android:layout_marginTop="28dp"
android:textOff="女"
android:textOn="男"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/editText3" />
而我们点击的时候,可以设置点击事件来获取到我们当前按钮上显示的值。
public void test(View view){
ToggleButton button =view;
Toast.makeText(this,button.getText(),0).show;
}
RadioGroup单选按钮
多选按钮格式如下
<RadioGroup
android:id="@+id/radioGroup"
android:layout_width="106dp"