我正在尝试动态设置复选框的背景颜色。谷歌搜索后,我发现了以下内容:
checkbox.setButtonDrawable(R.drawable.checkbox_background);
但不幸的是,它只会导致复选框背景消失。
任何建议或意见都会有所帮助!
下面是用作复选框背景的 xml 文件:
checkbox_background.xml
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<stroke
android:width="1dp"
android:color="@color/off_white"/>
</shape>
最佳答案
你需要设置drawable的大小
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<size android:height="20dp" android:width="20dp"/>
<stroke
android:width="1dp"
android:color="@color/off_white"/>
</shape>
关于Android:动态设置复选框背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22951326/