我需要有自定义的复选框,这不是那么棘手。我做了checkbox_selector来绘制文件夹:如何为所有元素设置相同的选择器?
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="false" android:drawable="@drawable/checkbox_disabled" /><!-- disabled -->
<item android:state_checked="false" android:state_pressed="true" android:drawable="@drawable/checkbox_unchecked_focused" /><!-- pressing unchecked box -->
<item android:state_checked="true" android:state_pressed="true" android:drawable="@drawable/checkbox_checked_focused" /><!-- pressing checked box -->
<item android:state_checked="true" android:drawable="@drawable/checkbox_checked" /><!-- checked box -->
<item android:state_checked="false" android:drawable="@drawable/checkbox_unchecked" /><!-- unchecked box -->
</selector>
但问题是,每一个checkbutton我做,我已经添加
<Checkbox
android:button="@drawable/checkbox_selector" />
试图谷歌答案了一段时间,也许我可以”找到合适的单词。
我可以说在这个应用程序的每个复选框应该使用这个@ drawable/checkbox_selector吗?
编辑: 说在styles.xml
<style name="customCheckBox">
<item android:button>@drawable/checkbox_selector</item>
</style>
中的Android 2.3.3 为我工作但当我尝试过的Android 4.0.3这是行不通的。任何想法为什么是这样?
他会叫梃每一个复选框,同样的问题,甚至是坏 –
不,因为我可以在主题文件说< item name =“android:checkboxStyle”> @ style/customCheckBox – joonasj
您也可以在自定义复选框构造函数中设置样式。 – dreamtale