a.单个RadioButton在选中后,通过点击无法变为未选中
单个CheckBox在选中后。通过点击能够变为未选中
b.一组RadioButton。仅仅能同一时候选中一个
一组CheckBox,能同一时候选中多个
c.RadioButton在大部分UI框架中默认都以圆形表示
CheckBox在大部分UI框架中默认都以矩形表示
2.RadioButton和RadioGroup的关系:
a.RadioButton表示单个圆形单选框。而RadioGroup是能够容纳多个RadioButton的容器
b.每一个RadioGroup中的RadioButton同一时候仅仅能有一个被选中
c.不同的RadioGroup中的RadioButton互不相干,即假设组A中有一个选中了,组B中依旧能够有一个被选中
d.大部分场合下,一个RadioGroup中至少有2个RadioButton
e.大部分场合下,一个RadioGroup中的RadioButton默认会有一个被选中。并建议您将它放在RadioGroup中的起始位置
3.简介完后,先来看一下本应用中的效果图吧:
简单的一个弹出pop,然后里面提供了四种订单的状态,实现起来也不难,闲来看一下xml代码吧:
从xml布局文件里,看出使用了radiogroup,而且包括了四个radiobutton。
这样便能够实现出那个弹出的popUpWindow.而且在RadioButton的图片中使用了状态选择器,分别在按下 选中和正常状态下,显示三种不同色值得图片,以一个为例。例如以下:
java代码例如以下,代码里都有凝视。目測能够看明确:
/** * 显示签收状态的pop */ private void showOrderStatusPop() { if (orderStatusPopView == null) { orderStatusPopView = View.inflate(mContext, R.layout.pop_bill_sort, null); } initOrderStatusPopView(); setCurrentCheckedItem(); setOrderStatusPopViewListener(); if (orderStatusPopupWindow == null) { orderStatusPopupWindow = new PopupWindow(orderStatusPopView, LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT); // 使其不聚集 orderStatusPopupWindow.setFocusable(false); // 设置同意在外点击消失 orderStatusPopupWindow.setOutsideTouchable(true); // 这个是为了点击“返回Back”也能使其消失,而且并不会影响你的背景 orderStatusPopupWindow.setBackgroundDrawable(new BitmapDrawable()); } int i = DensityUtil.dip2px(mContext, 60.0f); iv_arrow.setImageResource(R.drawable.arrow_up_float); orderStatusPopupWindow.showAsDropDown(top, 0, -i); } /** * 初始化订单状态控件 */ private void initOrderStatusPopView() { rl_order_parent = (RelativeLayout) orderStatusPopView .findViewById(R.id.rl_order_parent); btn_sort = (RadioGroup) orderStatusPopView.findViewById(R.id.btn_sort); btn_sort_all = (RadioButton) orderStatusPopView .findViewById(R.id.btn_sort_all); btn_sort_unsigned = (RadioButton) orderStatusPopView .findViewById(R.id.btn_sort_unsigned); btn_sort_signed = (RadioButton) orderStatusPopView .findViewById(R.id.btn_sort_signed); btn_sort_recycle = (RadioButton) orderStatusPopView .findViewById(R.id.btn_sort_recycle); } /** * 设置订单状态的监听 */ private void setOrderStatusPopViewListener() { rl_order_parent.setOnClickListener(this); btn_sort_all.setOnClickListener(this); btn_sort_unsigned.setOnClickListener(this); btn_sort_signed.setOnClickListener(this); btn_sort_recycle.setOnClickListener(this); //给radioGroup设置选中变化的监听。便于检測当前选中了哪个,方便下次再次显示回显 btn_sort.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, int checkedId) { switch (checkedId) { case R.id.btn_sort_all: currentCheckedId = checkedId; break; case R.id.btn_sort_unsigned: currentCheckedId = checkedId; break; case R.id.btn_sort_signed: currentCheckedId = checkedId; break; case R.id.btn_sort_recycle: currentCheckedId = checkedId; break; } } }); btn_sort.check(currentCheckedId); } /** * 设置当前显示的状态 */ private void setCurrentCheckedItem() { switch (currentCheckedId) { case R.id.btn_sort_all: resetTextColor(); btn_sort_all.setTextColor(mContext.getResources().getColor( R.color.blue_kuaidi100)); break; case R.id.btn_sort_unsigned: resetTextColor(); btn_sort_unsigned.setTextColor(mContext.getResources().getColor( R.color.blue_kuaidi100)); break; case R.id.btn_sort_signed: resetTextColor(); btn_sort_signed.setTextColor(mContext.getResources().getColor( R.color.blue_kuaidi100)); break; case R.id.btn_sort_recycle: resetTextColor(); btn_sort_recycle.setTextColor(mContext.getResources().getColor( R.color.blue_kuaidi100)); break; } } /** * 重置文字颜色 */ private void resetTextColor() { btn_sort_all.setTextColor(mContext.getResources().getColor( R.color.grey_878787)); btn_sort_unsigned.setTextColor(mContext.getResources().getColor( R.color.grey_878787)); btn_sort_signed.setTextColor(mContext.getResources().getColor( R.color.grey_878787)); btn_sort_recycle.setTextColor(mContext.getResources().getColor( R.color.grey_878787)); }
这样,便实现了一个pop的弹出和radioGroup radioButton的一个结合,事实上在实际应用中,底部使用RadioGroup的应用也不少,大同小异,关于这个小知识点就介绍到这了。