如何更改复选框中按钮的大小

How to change button's size in checkbox

我尝试使用 png 文件更改 Checkbox 中的 Button,但是图像太大,导致 Button 太大。

我想将按钮的大小更改为 20dp。 然后我在CheckBox里面设置了layout_width和layout_height,还是没有解决问题

你能教我如何改变尺寸吗?

<CheckBox
    android:layout_width="20dp"
    android:layout_height="20dp"
    android:text="New CheckBox" 
    android:layout_margin="5dp"
    android:button="@drawable/my_check_box"
    android:layout_weight="1" />

my_check_box.xml

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

您需要为其设置相关的drawable

<CheckBox 
android:layout_width="wrap_content" 
android:layout_height="wrap_content"
android:text="new checkbox" 
android:background="@drawable/my_checkbox_background"
android:button="@drawable/my_checkbox" />

这个link有很好的例子 Custom Checkbox