1.基本用法与事件处理:
1)RadioButton(单选按钮)
单选按钮就是一组单选按钮中只能选择一个,所以我们需要把RadioButton放到RadioGroup按钮组中,从而实现 单选功能!
布局文件xml中的代码如下
<?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"
android:orientation="vertical">
<TextView
android:id="@+id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/text1_value"
android:textSize="20sp" />
<!--自定义的单选-->
<RadioGroup
android:id="@+id/RadioGroup1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<RadioButton
android:id="@+id/radiobutton1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/select_style"
android:gravity="left|center"
android:text="维护"/>
<RadioButton
android:id="@+id/radiobutton2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/select_style"
android:gravity="left|center"
android:text="实现"/>
<RadioButton
android:id="@+id/radiobutton3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/select_style"
android:gravity="left|center"
android:text="保障"/>
<RadioButton
android:id="@+id/radiobutton4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/select_style"
android:gravity="left|center"
android:text="发展"/>
<RadioButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:button="@null"
android:visibility="invisible"
android:background="@drawable/shape"
android:text="this is demo"/>
</RadioGroup>
<!--非自定义的单选-->
<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="单选1"
android:checked="true"/>
<RadioButton