【发布时间】:2015-09-19 22:22:24
【问题描述】:
我尝试使用以下内容制作 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));
在这个问题之后:Change icons of checked and unchecked for Checkbox for Android 我需要用我的 xml 设置 button drawable:android:button="@drawable/checkbox" 但我不能这样做,因为我正在以编程方式创建 CheckBox。
有没有办法做到这一点?
【问题讨论】:
-
你尝试过 yourcheckbox.setButtonDrawable();
-
我不知道有这样的命令,请将其发布为帮助他人的答案。
-
你试过我的代码了吗