android开发的CheckBox和RadioButton
2017-11-21 20:38
260 查看
1、改变选择框:以RadioButton为例
<RadioButton xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/rb_question"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textColor="@color/c_22"
android:button="@null"
android:drawableLeft="@drawable/radio_question_state"
android:drawablePadding="@dimen/d16px"
android:textSize="@dimen/s32px"
android:paddingBottom="@dimen/d30px"
>
</RadioButton>
在drawable中新建radio_question_state
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_checked="false"
android:drawable="@mipmap/radio_answer_normal"/>
<item
android:state_checked="true"
android:drawable="@mipmap/radio_answer_select"/>
</selector>2、选中状态判断
CheckBox:
cb.setId(i);
cb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
listAnswer.getAnswer().get(compoundButton.getId()).setSelect(isChecked);
}
});RadioButton:
radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup radioGroup, int checkId) {
listAnswer.getAnswer().get(checkId).setSelect(true);
b7ac
if(ActivityUtils.isActivityExist(QuestionActivity.class)){
ActivityUtils.getActivity(QuestionActivity.class).setQuestionListBean(number,listAnswer);
}
}
});
注:尽量不要在自定义控件中设置改变drawableLeft,会出现些奇葩的问题。
最好用CheckBox cb = UIUtils.inflate(context,R.layout.check_question).findViewById(R.id.cb_answer)方式引用;
<RadioButton xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/rb_question"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textColor="@color/c_22"
android:button="@null"
android:drawableLeft="@drawable/radio_question_state"
android:drawablePadding="@dimen/d16px"
android:textSize="@dimen/s32px"
android:paddingBottom="@dimen/d30px"
>
</RadioButton>
在drawable中新建radio_question_state
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_checked="false"
android:drawable="@mipmap/radio_answer_normal"/>
<item
android:state_checked="true"
android:drawable="@mipmap/radio_answer_select"/>
</selector>2、选中状态判断
CheckBox:
cb.setId(i);
cb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
listAnswer.getAnswer().get(compoundButton.getId()).setSelect(isChecked);
}
});RadioButton:
radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup radioGroup, int checkId) {
listAnswer.getAnswer().get(checkId).setSelect(true);
b7ac
if(ActivityUtils.isActivityExist(QuestionActivity.class)){
ActivityUtils.getActivity(QuestionActivity.class).setQuestionListBean(number,listAnswer);
}
}
});
注:尽量不要在自定义控件中设置改变drawableLeft,会出现些奇葩的问题。
最好用CheckBox cb = UIUtils.inflate(context,R.layout.check_question).findViewById(R.id.cb_answer)方式引用;
相关文章推荐
- Android开发--RadioButton和CheckBox控件的使用
- mars android开发之六:radioButton与checkbox
- Android开发中关于Spinner;Checkbox; RadioButton; EditText;怎样向其他Ativity传值
- 4.Android 游戏开发常用的系统控件(EditText、CheckBox、Radiobutton)
- Android开发视频教程之十二(RadioGroup、RadioButton、CheckBox和Toast的使用)
- Android开发学习笔记:RadioButton和CheckBox浅析
- 【按住你的心】——Android开发CheckBox&RadioButton控件的简单使用
- Android入门笔记 - 界面开发 - RadioButton,CheckBox,Spinner,AutoCompleteTextView,DatePicker,TimePicker
- Android开发之组件单选框(RadioButton)多选框(CheckBox)下拉框(Spinner)
- Android开发历程_6(RadioButton和CheckBox的使用)
- Android开发学习笔记:RadioButton和CheckBox浅析
- Android开发学习笔记——浅谈RadioButton和CheckBox
- 【读书笔记《Android游戏编程之从零开始》】4.Android 游戏开发常用的系统控件(EditText、CheckBox、Radiobutton)
- Android开发--控件之RadioGroup、RadioButton、CheckBox、Toast
- 【读书笔记-《Android游戏编程之从零开始》】4.Android 游戏开发常用的系统控件(EditText、CheckBox、Radiobutton)
- Android开发之RadioButton和CheckBox
- 【读书笔记《Android游戏编程之从零开始》】4.Android 游戏开发常用的系统控件(EditText、CheckBox、Radiobutton)
- 【按住你的心】——Android开发CheckBox&RadioButton控件的简单使用
- Android开发--RadioButton和CheckBox控件的使用
- Android 常用控件自定义样式RadioButton、CheckBox、ProgressBar、