1.RadioButton和CheckBox的介绍
RadioButton(单选按钮)和CheckBox(复选框)是用户界面中最普通的UI组件,它们都继承自Button类,因此可以直接使用Button支持的各种属性和方法。
RadioButton和CheckBox都多了一个可选中的功能,因此可以额外指定一个android:checked属性,用于指定RadioButton和CheckButton初始时是否被选中。
RadioButton和CheckBox的不同之处在于,一组RadioButton只能选中其中一个,因此RadioButton通常要和RadioGroup一起使用,用来定义一组单选按钮。
2.RadioButton和CheckBox使用实例
2.1布局界面代码
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
tools:context=".MainActivity">
<RadioGroup