关于单选框RadioGroup和RadioButton
16lz
2021-01-23
<RadioGroup android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="10dp" android:orientation="horizontal" android:checkedButton="@+id/rb_male" > <RadioButton android:id="@+id/rb_male" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="男" android:textColor="@color/black" /> <RadioButton android:id="@+id/rb_female" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="10dp" android:text="女" android:textColor="@color/black" /> </RadioGroup>
以上示例可以完成一个单选框,注意的是RadioGroup中的属性android:checkedButton="@+id/rb_male",这个是指默认选中的按钮。如果不在这里设置,直接在下边的某个RadioButton中设置属性android:checked="true",这种情况下,在运行时,两个RadioButton都可以被选中。
更多相关文章
- Android NDK开发动态加载so示例源码
- Android 属性动画(Property Animation) 完全解析 (上)
- EditText属性详解
- android自定义视图属性(atts.xml,TypedArray)学习