如何在Android中通过编程方式更改复选框边框颜色?边框、复选框、颜色、方式

2023-09-06 05:19:40 作者:自甘堕落

在我的XML包含一个复选框。如何在Android中通过编程方式更改复选框边框颜色。

In my XML contains one CheckBox. How to change check box border color via programmatically in android.

我的样本屏幕截图是在这里 截图

My Sample ScreenShot is here ScreenShot

感谢。

推荐答案

您可以设置 check.setButtonDrawable(mContext.getResources()。getDrawable(                     R.drawable.radio));

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

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

in radio.xml you can set any background to your check box.

在radio.xml

in radio.xml

<?xml version="1.0" encoding="utf-8"?>

<item android:drawable="@drawable/option_unselected" android:state_checked="false"/>
<item android:drawable="@drawable/option_selected" android:state_checked="true"/>

在这里option_selected和option_selected是图形选择和unslected状态。

here option_selected and option_selected are the graphics for selected and unslected state.

了解更多,您可以检查的http://developer.android.com/guide/topics/resources/drawable-resource.html#StateList

for more you can check http://developer.android.com/guide/topics/resources/drawable-resource.html#StateList