CheckBox复选框默认情况下是未选中状态,如果想修改这个默认值的话,可以将中的android:checked设置为true或者使用CheckBox.setChecked方法设置都可以实现复选的功能。
实现案例如下图:
首先配置xml文件,本项目使用的是嵌套方法,创建了两个xml文件,第一个是主xml文件,设置了textview和button,有添加了一个LinearLayout组件用来嵌套checkBox
主xml文件配置代码如下:
<TextView
android:id="@+id/tv_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="单选"
android:textColor="@android:color/background_dark"
android:textSize="33dp"
/>
<LinearLayout
android:id="@+id/ll_checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" />