给CheckBox换样式

 

 

1、声明一个CheckBox,并设置style

<CheckBox android:textColor="#7fffffff" android:id="@+id/login_cb_receivegroupmsg"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:text="@string/opt_acceptGroupMsg" style="@style/MyCheckBox" />

2、编写style样式

<resources>
<style name="MyCheckBox" parent="@android:style/Widget.CompoundButton.CheckBox">
<item name="android:textSize">16.0sp</item>
<item name="android:textColor">@color/qq_checkbox_text_color</item>
<item name="android:paddingLeft">28.0px</item>
<item name="android:button">@drawable/qq_btn_check</item>
</style>
</resources>

3、定义qq_btn_check.xml作为背景

 <?xml version="1.0" encoding="UTF-8"?>
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_window_focused="false" android:state_enabled="true" android:state_checked="true" android:drawable="@drawable/btn_check_on" />
<item android:state_window_focused="false" android:state_enabled="true" android:state_checked="false" android:drawable="@drawable/btn_check_off" />
<item android:state_enabled="true" android:state_checked="true" android:state_pressed="true" android:drawable="@drawable/btn_check_on_pressed" />
<item android:state_enabled="true" android:state_checked="false" android:state_pressed="true" android:drawable="@drawable/btn_check_off_pressed" />
<item android:state_focused="true" android:state_enabled="true" android:state_checked="true" android:drawable="@drawable/btn_check_on_selected" />
<item android:state_focused="true" android:state_enabled="true" android:state_checked="false" android:drawable="@drawable/btn_check_off_selected" />
<item android:state_enabled="true" android:state_checked="false" android:drawable="@drawable/btn_check_off" />
<item android:state_enabled="true" android:state_checked="true" android:drawable="@drawable/btn_check_on" />
</selector>

 

本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/fsfcvictor/archive/2010/10/21/5957580.aspx

你可能感兴趣的:(android,qq,layout,button,encoding,2010)