0

I'm trying to change the color of a checkbox but its not working. How to change the color of checkbox after it's checked? I'm applying a theme but its not working:

<item
    android:id="@+id/tagsSelectAll_menu"
    app:actionViewClass="android.support.v7.widget.AppCompatCheckBox"
    android:checkable="true"    
    android:theme="@style/WhiteCheck"
    app:showAsAction="always"
    android:title="SelectAll"/>
Srinivas Ch
  • 1,202
  • 2
  • 19
  • 34
  • Possible duplicate of [How to change the color of a CheckBox?](http://stackoverflow.com/questions/5854047/how-to-change-the-color-of-a-checkbox) – Robb1 Jan 03 '17 at 16:41

2 Answers2

0

I think the problem for you was to get the actual reference to the Checkbox. You can do that either through onCreateOptionsMenu() or onOptionsItemSelected() depending on your use case. Keep the reference to that Checkbox and update the color after some event.

@Override
public boolean onCreateOptionsMenu(final Menu menu) {
    MenuItem item = menu.findItem(R.menu.your_menu_item);
    // `checkbox` is a field of the class
    checkbox = (Checkbox) item.getActionView().findViewById(R.id.my_checkbox);
}

How to change the color of a CheckBox?

Community
  • 1
  • 1
azizbekian
  • 60,783
  • 13
  • 169
  • 249
-1
Try this,

    <item
     android:id="@+id/tagsSelectAll_menu"
     app:actionViewClass="android.support.v7.widget.AppCompatCheckBox"
     android:checkable="true"    
     android:theme="@style/WhiteCheck"
     app:showAsAction="always"
     android:background="@drawable/button_states"
     android:title="SelectAll"    
    />


button_states xml:-

<?xml version="1.0" encoding="UTF-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="false">
<shape android:shape="rectangle">
<corners android:radius="1000dp"/>
<solid android:color="#00000000"/>
<stroke android:color="#00000000" android:width="2dip"/>
<padding android:top="4dp" android:right="4dp" android:left="4dp" android:bottom="4dp"/>
</shape>
</item>
<item android:state_pressed="true">
<shape android:shape="rectangle">
<corners android:radius="1000dp"/>
<solid android:color="#00000000"/>
<stroke android:color="#00000000" android:width="2dip"/>
<padding android:top="4dp" android:right="4dp" android:left="4dp" android:bottom="4dp"/>
</shape>
</item>
</selector>
santosh kumar
  • 2,952
  • 1
  • 15
  • 27