如何创建矩形自定义单选按钮或复选框?

How to create Rectangle custom Radio Button or CheckBox?

如何创建像给定图像一样的自定义复选框?我应该用单选按钮来做,因为颜色的填充看起来像一个单选按钮吗?如果是,如何使用单选按钮来完成?

你可以从这里开始

  1. 创建自定义绘图,your_awesome_checkbox.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
    <item android:state_checked="true" android:drawable="@drawable/ic_awesome_chb_checked" />
    <item android:state_pressed="true" android:drawable="@drawable/ic_awesome_chb_checked" />
    <item android:state_pressed="false" android:drawable="@drawable/ic_awesome_chb_unchecked" />
</selector>

并将此可绘制对象设置为您的复选框,例如

android:button="@drawable/your_awesome_checkbox"

在上面的代码中

  1. ic_awesome_chb_checked:这个图标代表复选框的选中状态。就像您添加到问题中的状态。
  2. ic_awesome_chb_unchecked:表示Checkbox的默认状态,未选中。