3

在我的 XML 中包含一个CheckBox. 如何在android中以编程方式更改复选框边框颜色。

我的示例屏幕截图在这里 ScreenShot

谢谢。

4

1 回答 1

3

你可以设置

check.setButtonDrawable(mContext.getResources().getDrawable(
                    R.drawable.radio));

radio.xml您可以为您的复选框设置任何背景。

在 radio.xml 中

<?xml version="1.0" encoding="utf-8"?>
 <selector xmlns:android="http://schemas.android.com/apk/res/android">
     <item android:drawable="@drawable/option_unselected" android:state_checked="false"/>
     <item android:drawable="@drawable/option_selected" android:state_checked="true"/>
 </selector>

这里 option_selected 和 option_selected 是选中和未选中状态的图形。

有关更多信息,您可以查看http://developer.android.com/guide/topics/resources/drawable-resource.html#StateList

于 2012-07-02T06:47:42.177 回答