android checkBox背景样式及用颜色值实现button点击效果

1? 使用颜色值(不使用图片)来实现按钮的点击效果:

color.xml

?<color name=”head_color”>#836FFF</color>

??? <color name=”information_title_color”>#666666</color>

??? <color name=”list_bg_color”>#FFF4F4F4</color>

??? <color name=”list_focus_color”>#bdbdbd</color>

?? ?

??? <drawable name=”f4f4f4″>#f4f4f4</drawable>

??? <drawable name=”camera_back_press”>#1b1b1b</drawable>

??? <drawable name=”camera_back_default”>#2f2f2f</drawable>

drawable中的文件

<?xml version=”1.0″ encoding=”utf-8″?>

<selector xmlns:android=”http://schemas.android.com/apk/res/android”>

??? <item android:drawable=”@drawable/camera_back_default” android:state_pressed=”false”></item>

??? <item android:drawable=”@drawable/camera_back_press” android:state_pressed=”true”></item>

</selector>

2? checkBox,RadioButton,Star 设置button的背景图片及点击效果

一?? selector? 点击效果 ?

<selector xmlns:android=”http://schemas.android.com/apk/res/android”>

??? <item android:drawable=”@drawable/checkbox_click_true”? android:state_checked=”true”/>

??? <item android:drawable=”@drawable/checkbox_default” android:state_checked=”false” />

??? <item android:drawable=”@drawable/checkbox_default”></item>

??? <item android:drawable=”@drawable/checkbox_click_false” android:state_checkable=”false”></item>

</selector>

二? 为组建设置样式

<style name=”MyCheck_Box” parent=”@android:style/Widget.CompoundButton.CheckBox”>

??????? <item name=”android:button”>@drawable/check_box_selector</item>

??????? <item name=”android:paddingLeft”>5.0dip</item>

??????? <item name=”android:textSize”>14sp</item>

??? </style>

样式中必须设置parent为你要设置效果的组件

item 必须引用button元素。并设置为selector效果的资源文件

item能够设置button与文字之间的间距和文字大小等等

三?? 在布局文件里,该组件设置style属性

<CheckBox

??????????????????? android:id=”@+id/checkbox1″

??????????????????? style=”@style/MyCheck_Box”

??????????????????? android:layout_width=”match_parent”

??????????????????? android:layout_height=”wrap_content”

??????????????????? android:layout_weight=”1″

??????????????????? android:text=”足球”

??????????????????? android:paddingLeft=”18dp”

??????????????????? android:textColor=”@color/black_color”

??????????????????? android:textSize=”14sp” />

EditText。点击时选中内容。

首先要实现点击事件接口。

在监听中做例如以下处理:

mEdtCount.setText(mEdtCount.getText().toString());//加入这句后实现效果
?? ??? ??? ?Spannable content = mEdtCount.getText();
?? ??? ??? ?Selection.selectAll(content);