Android 自定义checkbox图片过大问题

2017-04-12  本文已影响557人  PeterHe888

首先我们新建一个drawable,属性是selector,设置俩张图片,用以checked时切换图片。

xml version="1.0"encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android"><itemandroid:drawable="@drawable/companion_open"android:state_checked="true">item><itemandroid:drawable="@drawable/companion_close"android:state_checked="false">item></selector>

然后定义一个style,CheckBox_style

<style name="wrist_light_screen_checkbox"parent="@android:style/Widget.CompoundButton.CheckBox">

<itemname="android:button">@nullitem><itemname="android:background">@drawable/checkbox_selectoritem>

</style>

注意parent所指定的style,以及item 的button,background的属性设定。

最后,在布局文件里使用CheckBox即可

<CheckBox android:id="@+id/cb_switch"

android:layout_width="45dp"

android:layout_height="45dp"

style="@style/wrist_light_screen_checkbox"/>

这样,CheckBox里的图片大小便得到了修改。

上一篇 下一篇

猜你喜欢

热点阅读