Android 开发第七讲 RadioButton (单选按钮) 一丶重构代码 之前我们响应按钮事件都是直接通过匿名内部类的方式. new一个对象来实现OnClick方法....> 界面则为下,选择男,则女就是未选中,否则就是相反 ?...因为他们在一个组里面.所以只能单选 2.2 RadioButton实现自定义 实现自定义还是使用 android:background属性,来制定一个选择状态的xml....来实现自定义的选中和未选中 但是前提要 设置 android:button="@null"才可以. 状态选择器XML如下 选择器 android:state_checked = true代表选中--> android:state_checked="true"> <!
CheckBox和RadioButton的用法 CheckBox,复选框,它允许用户选择一个或者多个。 RadioButton,单选按钮,只能选取一个选项。...-- android:checkedButton="@+id/radiobutton_apple" 表示默认选中的RadioButton; android:..." > RadioButton android:id="@+id/radiobutton_banana" android:layout_width...RadioButton android:id="@+id/radiobutton_apple" android:layout_width="wrap_content"...Toast.LENGTH_SHORT).show(); } else { Toast.makeText(CheckBoxRadioButtonActivity.this, "您取消了
超好用的类: 在项目直接写入,可以自定义选择器, package com.bestgo.callshow.custom_control; import android.content.Context...; import android.content.res.TypedArray; import android.graphics.Canvas; import android.graphics.Paint...; import android.graphics.Typeface; import android.os.Handler; import android.os.HandlerThread; import...android.os.Message; import android.support.v4.widget.ScrollerCompat; import android.text.TextPaint;...import android.text.TextUtils; import android.util.AttributeSet; import android.view.MotionEvent; import
相信用过RadioGroup的同学都踩过很多坑,其中之一就是这个控件设计的不是很合理,不能设置里面的radiobutton的 排列方式(几行几列),导致我们开发的时候要调整里面的布局很是麻烦。...android:padding="0dp"> RadioButton android:id="@+id/rb_1" android:layout_width...android:text="红色" /> RadioButton android:id="@+id/rb_2" android:layout_width...然后运行,点击选一下试试,woc,不对啊,这点击效果不对啊 ,发现原来默认选中的 没有取消选中啊,点击事件不对了啊,分分钟懵逼了... 所以其实原生的RadioGroup 存在的问题: 1....() > (r - l)) { //重置 preLeft = getPaddingLeft(); //要选择
首先说一下什么是RadioButton, 什么是RadioGroup RadioButton(单选按钮)顾名思义就是一组RadioButton只能选中其中一个。...通常RadioButton和RadioGroup是一起使用的。 如果RadioButton和另外的一个RadioButton不再同一组的话,那么这两个RadioButton都是可以同时被选中的。...而RadioButton的特殊之处就是可以选中的功能,所以RadioButton的事件就是OnCheckedChange(也就是选中或者取消选中改变的事件) RadioButton举例说明: public...布局文件也就是一个RadioGroup里面有3个RadioButton而已; 测试结果为下: 默认情况是3个都没有选择,只有一个选中就会显示选中。同时3个之中只能有一个同时被选中。...因为他们所属的包名都不一样 import android.widget.RadioGroup.OnCheckedChangeListener; (Radiogroup的所属包) import android.widget.CompoundButton.OnCheckedChangeListener
单选控件——RadioButton 一个普通单选控件的示例 android:layout_width=“wrap_content” android:layout_height...,在选择后将结果显示在TextView中。 ...总结:RadioButton和RadioGroup的关系: 1、RadioButton表示单个圆形单选框,而RadioGroup是可以容纳多个RadioButton的容器 2、每个RadioGroup...:src 设置要显示的图片源 android:scaleType 图片的填充方式 android:adjustViewBounds 是否保持宽高比 android:tint 图片的着色 对应的类是...1.为自动提示的下拉选择项提供显示布局 2.为下拉框提供内容数据 3.使用自动完成文本框 .自动完成文本框的常用属性 android:completionHint 定义下拉菜单的提示信息 android
按钮转向注册界面 三、用户注册界面 1、界面展示 2、所用控件: LinearLayout、TableLayout TextView、EditText、CheckBox、Button、RadioGroup、RadioButton...、RadioButton用法 android RadioGroup实现单选以及默认选中 - 推酷 android RadioButton怎么设置默认选中?...-CSDN论坛-CSDN.NET-中国最大的IT技术社区 5、婚否:ToggleButton用法 Android开发学习笔记:浅谈ToggleButton - IT的点点滴滴 - 51CTO技术博客...6、爱好:CheckBox用法 android CheckBox控件的定义及事件监听_干吃不胖大人逆天了_新浪博客 android checkBox 的选中和取消选中 - a79412906的专栏...四、登录查询 1、设置RadioButton,CheckBox,ToggleButton选中 xx.setChecked(true); 2、java中怎么把字符串转化为字符串数组?
"> <TextView android:layout_marginTop="20dp" android:textSize="20sp" android:text="请选择您最爱的职业...:text="请选择您最爱的职业:" android:textSize="20sp" /> <RadioGroup android:id="@+id/job_list...(单选)是RadioGroup内部自己管理的,这为我们节省很多的开发逻辑,也是我们用它的主要目的。...此外,这里,我们还可以通过调用clearCheck()实现清除选择状态。...(单选)是RadioGroup内部自己管理的,这为我们节省很多的开发逻辑,也是我们用它的主要目的。
场景 RadioButton 单选按钮 ,在实际开发中应用很广泛。一般用于实现控件设置选择样式或者有一组控件设置其中一个效果选中效果,例如微信底部 Tab栏切换效果等。...但是往往根据真实需求来开发的时候,需要设置 RadioButton的 background中的 selector才能实现效果。...的文本水平居中 android:gravity="center_horizontal" 给 RadioButton设置选中和未选中的样式选择器 在 drawable文件夹下新建四个 tab图标选择器,这里粘贴首页图标的选择器...为选择器样式,设置完四个 tab后代码如下: 选择器 * @param rb RadioButton的样式选择器 */ private void setStyle(int selector, RadioButton
if (type == 1) { eventSelected = position; //将选择的内容设置到底部的按钮上去...> android="http://schemas.android.com/apk/res/android" android:layout_width="...> android="http://schemas.android.com/apk/res/android" android:layout_width="...="40dp" android:button="@null" android:gravity="center" android:paddingBottom...= -1) { list.set(lastPosition, false);// 取消上一次的选中状态 } list.set(position,
我们在开发过程中经常会用到CheckBox、RadioButton、RatingBar、SeekBar 这几个控件,而系统默认的样式却不能满足我们的要求,通常我们会直接采用github的开源库来完成,...> RadioButton android:layout_width="wrap_content" android:layout_weight...android:theme="@style/FirstControl" /> RadioButton android:layout_weight="1"...> RadioButton android:layout_weight="1" android:layout_width="wrap_content...android:theme="@style/ThirdControl" /> RadioButton android:layout_weight="1"
为使单选按钮产生互斥效果,需要把所有RadioButton放置在一个统一的RadioGroup中。
本期先来学习Button的两个子控件,无论是单选还是复选,在实际开发中都是使用的较多的控件,相信通过本期的学习即可轻松掌握。..." android:text="选择喜欢的城市"/> <CheckBox android:id="@+id/shanghai_cb" android...二、RadioButton RadioButton(单选按钮)在Android开发中应用的非常广泛,比如一些选择项的时候,会用到单选按钮。它是一种单个圆形单选框双状态的按钮,可以选择或不选择。...在RadioButton没有被选中时,用户能够按下或点击来选中它。但是,与复选框相反,用户一旦选中就不能够取消选中。当用户选中的时候会触发一个OnCheckedChange事件。...在没有RadioGroup的情况下,RadioButton可以全部都选中;当多个RadioButton被RadioGroup包含的情况下,RadioButton只可以选择一个。
RadioButton 单选按钮:是可以选中或取消选中的双状态按钮。当单选按钮被取消选中时,用户可以单击来选中它。 注:单选按钮通常与RadioGroup在一起使用。...当多个单选按钮在RadioGroup内时,检查一个单选按钮将取消选中所有其他单选按钮。 android:layout_height="wrap_content" android:orientation="vertical"> RadioButton android:id="@...="@string/pirates" android:onClick="onRadioButtonClicked"/> RadioButton android:id="@+id/radio_ninjas...Switch 开关:是一个双状态切换开关小部件,可以在两个选项之间进行选择。用户可以来回拖动“拇指”来选择所选择的选项,或者只需轻按以切换,就像复选框一样。
在开发的早期阶段,这些控件应该完全能够满足开发者的要求.随着知识的不断深入,开发者完全可以根据自己的需要,自定义控件.这篇博文主要和大家介绍一下android内置的这些控件的简单用法...." android:orientation="horizontal" > RadioButton android:id="@+id/radioMale"..." android:layout_marginLeft="5dp" /> RadioButton android:id="@+id/radioFemale...="true" android:layout_toRightOf="@+id/bt_OK" android:text="取消" android:layout_marginLeft..., str); p.setAdapter(aa_spinner); } #2.radiobutton的取值,只需要判断isChecked(),两个RadioButton放在RadioGroup中
二.RadioGroup和RadioButton简单介绍 RadioButton即单选按钮,它在开发中提供了一种“多选一”的操作模式,是Android开发中常用的一种组件,例如在用户注册时,选择性别时只能从...- android.widget.RadioGroup RadioGroup提供的只是RadioButton单选按钮的容器,我们可以在该容器中添加多个RadioButton方可使用,要设置单选按钮的内容...RadioButton类的定义如下图所示: java.lang.Object - android.view.View - android.widget.TextView - android.widget.Button...- android.widget.CompoundButton - android.widget.RadioButton 可以发现RadioButton类是Button类的子类,因此该组件与Button...,当选择状态被清除,则单选按钮组里面的所有单选按钮将取消勾选状态,getCheckedRadioButtonId()将返回null public int getCheckedRadioButtonId
setScaleX(2.0f); 设置 TextView 行间距 Android TextView 默认显示中文时会比较紧凑,为了让每行保持的行间距,可以设置如下属性 如:setLineSpacing...RadioButton 继承自 Button,所以拥有 Button 的所有公开属性和方法 RadioButton 只有两个状态,选中与未选中,所以也就只有一个属性是最重要的,那就是 android:...checked android:checked 设置或获取 RadioButton 的选中状态 如果 RadioButton 未选中,那么点击它可以让它选中,但反过来是不可以的,就是不能从选中状态到未选中状态...在多个 RadioButton被 RadioGroup 包含的情况下,同一时刻只可以选择一个 RadioButton,并用 setOnCheckedChangeListener 来对 RadioGroup... 组在一起形成单选按钮组,实现单选功能,也就是选中一个,会取消其它选项的选中 RadioGroup 只提供了一个 XML 属性 android:checkedButton 用于指定初始化时选中的 ID
Android视图控件ImageView控件,本文我们继续盘点,介绍一下视图控件的第五个控件——RadioButton。...一.RadioButton基本介绍 在 Android 应用开发中,RadioButton是单选按钮,允许用户在一个组中选择一个选项。同一组中的单选按钮有互斥效果。...),导致我们开发的时候要调整里面的布局很是麻烦。...单选换行功能 Android 实现radiobutton单选换行效果 四.基础DEMO示例 activity_radiobutton.xml RadioButton android:id="@+id/radioButton2" android:layout_width="wrap_content
,而我们实际开发中用的是它的几个派生类,如复选框CheckBox、单选按钮RadioButton单选按钮、Switch开关按钮,这些派生类均可使用CompoundButton的属性和方法。...1.3 单选按钮RadioButton 单选按钮要在一组按钮中选择其中一项,并且不能多选,这要求有个容器确定这组按钮的范围,这个容器便是单选组RadioGroup,单选组RadioGroup实质上是一个布局...单选按钮RadioButton默认是未选中状态,点击它则显示选中状态,但是再次点击并不会取消选择,只有点击同组的其他单选按钮,原来选中的单选按钮才会被取消选中。...:text="请选择您的性别" android:layout_width="wrap_content" android:layout_height="wrap_content...:text="请选择开关" android:layout_width="wrap_content" android:layout_height="wrap_content
实际开发中用的是它的两个派生类,分别是CheckBox和RadioButton,派生类继承了CompoundButton新增的属性和方法。...RadioButton是单选框,点击选中,但是再点击不会取消选中。...只有点击同组的其他RadioButton,原来勾选的RadioButton才会取消选中。...RadioGroup是容纳多个RadioButton的组布局,同组中只能有一个RadioButton被选中。...="false" android:drawableLeft="@drawable/ck_switch_selector" /> 点此查看Android开发笔记的完整目录
领取专属 10元无门槛券
手把手带您无忧上云