更改Android的复选框的背景颜色 [英] change checkbox background color in android
问题描述
我要制订一个app.here我必须使用checkbox.here我必须选择复选框意味着默认的背景色yellow.but我希望为更改使用梯度选中和未选中状态的背景颜色.how我可以改变this.please帮助我。
这是我目前的code:
<复选框
机器人:ID =@ + ID / rempasswordcheckbox
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_below =@ + ID / passwordview
机器人:layout_y =200dp
机器人:以下属性来=45dp
机器人:文本=记住密码!
机器人:文字颜色=#1d2328/>
如果您对我们改变复选框(按钮)的背景色用
mcheckbox.setButtonDrawable(R.drawable.someotherbackground);
在这里someotherbackground是到后台,你希望你的复选框要更改的文件夹绘制的图像
尝试如下
mcheckbox.setOnCheckedChangeListener(新OnCheckedChangeListener(){
公共无效onCheckedChanged(CompoundButton buttonView,
布尔器isChecked){
如果(器isChecked){
的System.out.println(选中+器isChecked);
mcheckbox.setButtonDrawable(R.drawable.imageWhenActive);
的System.out.println(应用程序常数被设置为+器isChecked);
}
其他
{
mcheckbox.setButtonDrawable(R.drawable.imageWheninactive);
的System.out.println(应用程序常数被设置为+器isChecked);
}
}
});
i have to develop one app.here i have to use checkbox.here i have to select checkbox means the default background color is yellow.but i wish to change the background color using gradient for checked and unchecked condition.how can i change this.please help me.
this is my current code:
<CheckBox
android:id="@+id/rempasswordcheckbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/passwordview"
android:layout_y="200dp"
android:paddingLeft="45dp"
android:text="Remember Password!"
android:textColor="#1d2328" />
if you are intersted to change the background color of the checkbox (button) use
mcheckbox.setButtonDrawable(R.drawable.someotherbackground);
where someotherbackground is an image in the drawable folder to which background you want your checkbox to be changed
try as below
mcheckbox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
if (isChecked) {
System.out.println("checked" + isChecked);
mcheckbox.setButtonDrawable(R.drawable.imageWhenActive);
System.out.println("app constant is set as "+isChecked);
}
else
{
mcheckbox.setButtonDrawable(R.drawable.imageWheninactive);
System.out.println("app constant is set as "+isChecked);
}
}
});
这篇关于更改Android的复选框的背景颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!