分类:C#、Android、VS2015;

创建日期:2016-02-07

一、简介

1、CheckBox

复选

【Checked】属性:是否选中。

2、RadioButton

单选

【Checked】属性:是否选中。

【RadioGroup】属性:RadioButton的分组容器。注意必须将RadioButton包含在RadioGroup内。

二、示例4—Demo04CheckBoxRadioButton

1、运行截图

2、添加demo04_CheckBoxRadioButton.axml文件

在layout文件夹下添加该文件。

从【工具箱】中向设计界面拖放2个【CheckBox】控件,1个【RadioGroup】控件,然后直接在【源】中将其修改为下面的内容:

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:orientation="vertical"    android:layout_width="match_parent"    android:layout_height="match_parent">    <CheckBox        android:text="红色"        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:id="@+id/checkBoxRed" />    <CheckBox        android:text="绿色"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:id="@+id/checkBoxGreen" />    <RadioGroup        android:minWidth="25px"        android:minHeight="25px"        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:id="@+id/radioGroupGander">        <RadioButton            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:checked="true"            android:text="男"            android:id="@+id/radioButtonMale" />        <RadioButton            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:text="女"            android:id="@+id/radioButtonFamale" />    RadioGroup>    <Button        android:id="@+id/btnOK"        android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:text="确定" />LinearLayout>

3、添加Demo04CheckBoxRadioButton.cs文件

在SrcActivity文件夹下添加该文件。

using System;using Android.App;using Android.OS;using Android.Widget;namespace ch05demos.SrcActivity{    [Activity(Label = "CheckBoxRadioButtonDemo")]    public class Demo04CheckBoxRadioButton : Activity    {        CheckBox red, green;        RadioButton nan, nv;        protected override void OnCreate(Bundle savedInstanceState)        {            base.OnCreate(savedInstanceState);            SetContentView(Resource.Layout.demo04_CheckBoxRadioButton);            red = FindViewById(Resource.Id.checkBoxRed);            green = FindViewById(Resource.Id.checkBoxGreen);            nan = FindViewById(Resource.Id.radioButtonMale);            nv = FindViewById(Resource.Id.radioButtonFamale);            var button = FindViewById

运行观察该例子的效果。

提示:通过【Checked】属性或Toggle()方法都可以改变RadioButton的状态。

更多相关文章

  1. Android(安卓)如何通过menu id来得到menu item 控件--binbinyang
  2. Android(安卓)平板 控制软键盘只弹出一半,自动盯着界面中EditText
  3. Android(安卓)实现适配器中的子控件与Activity通信
  4. 更改Android(安卓)AppCompatRadioButton控件的样式和颜色
  5. Android(安卓)Studio 开关控件Switch使用
  6. 控件显示和隐藏
  7. Android(安卓)8.0 添加HIDL
  8. 在Androd studio 中,TextView设置Text居然都是大写
  9. Android(安卓)ConstraintLayout 布局解析

随机推荐

  1. HTML5在Android(安卓)IOS等移动平台上的
  2. Android(安卓)Studio 2.0带来的新特性
  3. 用Dbus与android的bluz通信
  4. android按键静音键功能实现
  5. android 开发之旅
  6. android基本动画,代码构建动画
  7. 安卓开发36:layout对齐属性总结
  8. 高手速成android开源项目【tool篇】
  9. Android原生游戏开发:使用JustWeEngine开
  10. Android之进度条控件和常用资源分类总结