本文介绍了在android中更改复选框背景颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我必须开发一个应用程序.这里我必须使用复选框.这里我必须选择复选框意味着默认背景颜色为黄色.但我希望使用渐变更改背景颜色以用于选中和未选中的条件.我该如何改变这个.请帮助我.
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.
这是我当前的代码:
<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);
其中 someotherbackground 是可绘制文件夹中的图像,您希望将复选框更改为该背景
where someotherbackground is an image in the drawable folder to which background you want your checkbox to be changed
尝试如下
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中更改复选框背景颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!