1.改变CheckBox的默认样式,
由方形变成自定义的形状,具体步骤如下:
a> 定义drawable.xml文件,指定CheckBox的button 属性,
drawable.xml如下所示“:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true" android:state_focused="true"
android:drawable="@drawable/checkbox_on" />
<item android:state_checked="false" android:state_focused="true"
android:drawable="@drawable/checkbox_off" />
<item android:state_checked="false"
android:drawable="@drawable/checkbox_off" />
<item android:state_checked="true"
android:drawable="@drawable/checkbox_on" />
</selector>
在使用CheckBox的xml布局文件里,使用属性button指定刚才的drawable.xml,
<CheckBox
android:id="@+id/checkbox"
android:layout_width="wrap_content"
android:button="@drawable/checkbox"
android:layout_gravity="center"
android:gravity="center"
android:layout_centerInParent="true"
android:layout_height="match_parent"
/>
效果如下:
2.改变Button的样式:
a>改变Button的按下按上效果:
定义drawable.xml文件,设定按下和按上的效果,
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/btn_cancel_pressed_1margin" android:state_pressed="true"
/>
<item android:drawable="@drawable/btn_cancel_normal_1margin"/>
</selector>
然后指定Button的background属性即可
b>改变Button 按下和按上时的字体颜色
定义drawable.xml,设定按下和按上时的字体颜色,如下:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:color="@color/white"/>
<item android:state_focused="true" android:color="@color/white"/>
<item android:color="@color/common_orange" />
</selector>
然后指定Button的textColor 属性
完整代码:
<Button android:layout_width="@dimen/intro_post_130"
android:layout_height="@dimen/intro_margin_40"
android:textSize="@dimen/intro_margin_15"
style="@style/dialog_btn_cancel"
android:id="@+id/btn_cancel_mile"
android:textColor="@drawable/button_font_style"
android:layout_margin="@dimen/intro_margin_10"
android:layout_centerVertical="true"
android:background="@drawable/btn_cancel_1margin"
android:text="@string/button_cancel"
/>
3.改变CheckedTextView的样式更改
a> 定义drawable.xml文件,和CheckBox指定的button 属性文件一样
b>在代码中设置:
checkedTextView.setCheckMarkDrawable(R.drawable.checkbox_selector_drawable);