Android 给CheckBox设置背景

一般来说我们给控件(Button,LinearLayout,ImageView,TextView等)设这背景的时候只需要设置这些控件的android:background即可,

但是在给CheckBox设置背景的时候这样设置就会出现背景图片偏大的问题。

怎么保证给CheckBox设置的背景大小正合适呢?请看如下代码:

 <CheckBox
                        android:id="@+id/orderpay_cb_zhifubao"
                        android:layout_width="wrap_content"
                        android:layout_marginLeft="20dp"
                        android:layout_height="wrap_content"
                        android:button="@drawable/xml_cb" />

我们只需要设置android:button="@drawable/图片的背景id"即可。

这是经过测试的,大家放心使用。

原文地址:https://www.cnblogs.com/tony-yang-flutter/p/3338435.html