我尝试使用以下内容创建了一个XML选择器:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/shuffleon" android:state_checked="true" />
<item android:drawable="@drawable/shuffleoff" android:state_selected="false" />
</selector>
当我尝试将backgroundDrawable
设置为CheckBox
时,复选框并没有替换CheckBox
的风格:
shuffle.setBackground(android.support.v4.content.res.ResourcesCompat.getDrawable(getResources(), R.drawable.shuffle, null));
在这个问题的基础上:如何更改Android CheckBox的选中和未选中图标,我需要通过XML设置button drawable
:android:button="@drawable/checkbox"
但是我无法这样做,因为我正在以编程方式创建CheckBox
。