Q:

change checkbox background color in 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.  
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" />

A:

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);
            }

        }
    });

A:

res/drawable/checkbox_background.xml:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
    <item android:state_checked="true">
        <shape>
            <gradient android:startColor="#FFFFFF" android:endColor="#000000" android:angle="-90"/>
        </shape>
    </item>
    <item>
        <shape>
            <gradient android:startColor="#000000" android:endColor="#FFFFFF" android:angle="-90"/>
        </shape>
    </item>
</selector>

In your layout:
<CheckBox ...
    android:button="@drawable/checkbox_background" />

If you want to use existing drawables:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
    <item android:state_checked="true" android:drawable="@drawable/checked_drawable" />
    <item android:drawable="@drawable/unchecked_drawable" />
</selector>

A:

Using Code . 
checkBox.setBackgroundColor(Color.BLUE);

Code
CheckBox cb = (CheckBox) findViewById(R.id.CheckBox01);
cb.setOnCheckedChangeListener(new OnCheckedChangeListener() 
{
     @Override
     public void onCheckedChanged(CompoundButton buttonView,boolean isChecked) 
     {
         // TODO Auto-generated method stub
         if (buttonView.isChecked()) 
         {
             //cb.setBackgroundColor(Color.BLUE);
             cb.setBackgroundColor(Color.parseColor("#FFFFFF"));
         }
         else
         {
             // Not Checked
             // Set Your Default Color. 
         }
     }
}); 

