<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都可以被选中。

更多相关文章

  1. Android NDK开发动态加载so示例源码
  2. Android 属性动画(Property Animation) 完全解析 (上)
  3. EditText属性详解
  4. android自定义视图属性(atts.xml,TypedArray)学习

随机推荐

  1. android混淆proguard
  2. Android无需root实现apk的静默安装
  3. 反弹效果实现
  4. 基于 CentOS 使用 Jenkins 实现 Android(
  5. Android中自定义属性的格式详解
  6. 将war包部署到android服务器上
  7. Android —— Retrofit 请求注解分析
  8. Android killer和Apktool回编译错误No re
  9. Android记事本NotePad应用功能拓展(五)
  10. Android开发之旅:应用程序基础及组件