RadioGroup修改默认小圆点

来源:互联网 发布:aso优化 app排名 编辑:程序博客网 时间:2024/06/05 10:53

1.使用XML文件进行定义选择器 res/drawable/radio.xml

  1. <?xml version="1.0" encoding="utf-8"?>     
  2. <selector xmlns:Android="http://schemas.android.com/apk/res/android">   
  3. <!-- 未选中->   
  4.     <item     
  5.          android:state_checked="false"     
  6.          android:drawable="@drawable/tabswitcher_long" />  
  7. <!--选中->     
  8.     <item     
  9.         android:state_checked="true"     
  10.         android:drawable="@drawable/tabswitcher_short" />     
  11. </selector>    
2.在布局文件中使用
  1. <RadioGroup  
  2.   ...  
  3. >  
  4. <RadioButton  
  5.   ...  
  6. android:button="@null"  
  7. android:background="@drawable/radio"  
  8. />  
  9. </RadioGroup>  
android:button="@null" 去除RadioButton前面的圆点

android:background="@drawable/radio"使用定义的样式

3.

4,为radioGroup添加监听事件,用来监听组件内部的事件响应:
作者: thermos
链接:http://www.imooc.com/article/2598
来源:慕课网
4,为radioGroup添加监听事件,用来监听组件内部的事件响应:
作者: thermos
链接:http://www.imooc.com/article/2598
来源:慕课网
为radioGroup添加监听事件,用来监听组件内部的事件响应:
作者: thermos
链接:http://www.imooc.com/article/2598
来源:慕课网
RadioGroup增加监听事件,

4.代码

  

<RadioGroup    android:id="@+id/grade_group"    android:paddingLeft="15dp"    android:orientation="horizontal"    android:layout_width="match_parent"    android:layout_height="wrap_content">    <RadioButton android:id="@+id/class_small"        android:background="@drawable/selector_radiogroup"        android:button="@null"        android:layout_width="wrap_content"        android:layout_height="wrap_content"/>    <TextView        android:id="@+id/small"        android:layout_gravity="center_vertical"        android:layout_marginLeft="12dp"        android:paddingRight="60dp"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="小班"        android:textSize="15dp"/>    <RadioButton        android:id="@+id/class_middle"        android:background="@drawable/selector_radiogroup"        android:button="@null"        android:layout_width="wrap_content"        android:layout_height="wrap_content"/>    <TextView        android:id="@+id/middle"        android:layout_gravity="center_vertical"        android:paddingRight="60dp"        android:layout_marginLeft="12dp"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="中班"        android:textSize="15dp"/>    <RadioButton        android:id="@+id/class_big"        android:background="@drawable/selector_radiogroup"        android:button="@null"        android:layout_width="wrap_content"        android:layout_height="wrap_content"/>    <TextView        android:id="@+id/big"        android:layout_gravity="center_vertical"        android:layout_marginLeft="12dp"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="大班"        android:textSize="15dp"/></RadioGroup>

    

rg_group.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {    @Override    public void onCheckedChanged(RadioGroup group, int checkedId) {        if (rb_small.getId() == checkedId) {            grade = small.getText().toString();        } else if (rb_middle.getId() == checkedId) {            grade = middle.getText().toString();        }else if(rb_big.getId() == checkedId){            grade = big.getText().toString();        }    }});
privateRadioGroup mSex_group;private RadioButton mMale;private RadioButton mFemale;private String sexName; mSex_group= (RadioGroup) findViewById(R.id.sex_group); mMale = (RadioButton) findViewById(R.id.male); mFemale = (RadioButton) findViewById(R.id.female); mSex_group.setOnCheckedChangeListener(newRadioGroup.OnCheckedChangeListener(){ @Overridepublic void onCheckedChanged(RadioGroupgroup,int checkedId){ if(mMale.getId()== checkedId){ sexName = mMale.getText().toString();} elseif (mFemale.getId()== checkedId){ sexName = mFemale.getText().toString();} }});
作者: thermos
链接:http://www.imooc.com/article/2598
来源:慕课网
privateRadioGroup mSex_group;private RadioButton mMale;private RadioButton mFemale;private String sexName; mSex_group= (RadioGroup) findViewById(R.id.sex_group); mMale = (RadioButton) findViewById(R.id.male); mFemale = (RadioButton) findViewById(R.id.female); mSex_group.setOnCheckedChangeListener(newRadioGroup.OnCheckedChangeListener(){ @Overridepublic void onCheckedChanged(RadioGroupgroup,int checkedId){ if(mMale.getId()== checkedId){ sexName = mMale.getText().toString();} elseif (mFemale.getId()== checkedId){ sexName = mFemale.getText().toString();} }});
作者: thermos
链接:http://www.imooc.com/article/2598
来源:慕课网
privateRadioGroup mSex_group;private RadioButton mMale;private RadioButton mFemale;private String sexName; mSex_group= (RadioGroup) findViewById(R.id.sex_group); mMale = (RadioButton) findViewById(R.id.male); mFemale = (RadioButton) findViewById(R.id.female); mSex_group.setOnCheckedChangeListener(newRadioGroup.OnCheckedChangeListener(){ @Overridepublic void onCheckedChanged(RadioGroupgroup,int checkedId){ if(mMale.getId()== checkedId){ sexName = mMale.getText().toString();} elseif (mFemale.getId()== checkedId){ sexName = mFemale.getText().toString();} }});
作者: thermos
链接:http://www.imooc.com/article/2598
来源:慕课网
privateRadioGroup mSex_group;private RadioButton mMale;private RadioButton mFemale;private String sexName; mSex_group= (RadioGroup) findViewById(R.id.sex_group); mMale = (RadioButton) findViewById(R.id.male); mFemale = (RadioButton) findViewById(R.id.female); mSex_group.setOnCheckedChangeListener(newRadioGroup.OnCheckedChangeListener(){ @Overridepublic void onCheckedChanged(RadioGroupgroup,int checkedId){ if(mMale.getId()== checkedId){ sexName = mMale.getText().toString();} elseif (mFemale.getId()== checkedId){ sexName = mFemale.getText().toString();} }});
作者: thermos
链接:http://www.imooc.com/article/2598
来源:慕课网
privateRadioGroup mSex_group;private RadioButton mMale;private RadioButton mFemale;private String sexName; mSex_group= (RadioGroup) findViewById(R.id.sex_group); mMale = (RadioButton) findViewById(R.id.male); mFemale = (RadioButton) findViewById(R.id.female); mSex_group.setOnCheckedChangeListener(newRadioGroup.OnCheckedChangeListener(){ @Overridepublic void onCheckedChanged(RadioGroupgroup,int checkedId){ if(mMale.getId()== checkedId){ sexName = mMale.getText().toString();} elseif (mFemale.getId()== checkedId){ sexName = mFemale.getText().toString();} }});
作者: thermos
链接:http://www.imooc.com/article/2598
来源:慕课网




0 0
原创粉丝点击