Android 自定义checkbox图片过大问题

首先我们新建一个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里的图片大小便得到了修改。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容