原创文章,如有转载,请注明出处:http://blog.csdn.net/myth13141314/article/details/72926013
RadioGroup
- 设置动态变化的背景
radioButton.setBackground(getResources().getDrawable(R.drawable.selector_rbtn_right_red_gray));
- 设置动态变化的字体颜色
radioButton.setTextColor(getResources().getColorStateList(R.color.rb_text_color));
- 编写color文件,color文件不同于drawable文件,需要单独在values文件夹下面新建color文件夹
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true" android:color="@color/std_c10"/>
<!-- not selected -->
<item android:state_checked="false" android:color="@color/std_c7"/>
</selector>
隐藏RadioGroup的默认样式
- 隐藏默认样式的方式:需要设置setButtonDrawable为透明色
radioButton.setButtonDrawable(android.R.color.transparent);
- 或者直接设置布局里的属性
android:button="@null"(无论4.4还是高版本都有效)
- 4.4系统上隐藏默认样式的坑:setButtonDrawable设置为null,在4.4及以下的系统上无效
radioButton.setButtonDrawable(null);
CheckBox
- 设置背景
<CheckBox
android:id="@+id/cbx_select_all"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:button="@null"
android:layout_marginRight="5dp"
android:background="@drawable/selector_checkbox_bg"/>
- 选中和未选中的背景
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true" android:drawable="@drawable/checkbox_select_icon"/>
<item android:state_checked="true" android:drawable="@drawable/checkbox_select_icon"/>
<item android:state_checked="false" android:drawable="@drawable/checkbox_unselect_icon"/>
<item android:state_selected="false" android:drawable="@drawable/checkbox_unselect_icon"/>
<item android:drawable="@drawable/checkbox_unselect_icon"/>
</selector>
欢迎关注我的公众号,和我一起每天进步一点点!