title: Change Checkbox background on click?
body: <p>I have a <code>Checkbox</code> with custom images inside a <code>selector</code>...</p>
  <img src="https://i.ibb.co/S55B6fq/Screenshot-1633605838.png" width="500">
  <p>and I am trying to achieve the following effect whnen the <code>checkbox</code> is clicked:</p>
  <p>Gif for reference:</p>
  <img src="https://i.ibb.co/j3NQ1Cb/ezgif-com-gif-maker.gif">
  <p>Tha background has to change while the <code>checkbox</code> is pressed and then goes back to normal when released.</p>
  <p>The first two buttons are <code>ImageButtons</code> and the effect was easily achieved but with <code>Checkbox</code> I'm struggling.
  I guess it has to be something with the <code>selector</code> itself but I am not quite sure how to implement it. I tried adding a <code>shape</code> inside an <code>item</code> and a <code>solid</code> color but I couldn't make it work. Please point me in the right direction.</p>
  <p>My checkbox code below <strong>(it uses two-way data binding)</strong>:</p>
  <pre><code> &lt;CheckBox
      android:id=&quot;@+id/btn_addtofavs&quot;
      android:layout_width=&quot;wrap_content&quot;
      android:layout_height=&quot;wrap_content&quot;
      android:layout_gravity=&quot;center&quot;
      android:background=&quot;@drawable/inflated_selector_is_checked&quot;
      android:button=&quot;@null&quot;
      android:checked=&quot;@={inflatedItemViewModel.item.checked}&quot;
      android:onClick=&quot;@{() -&gt; inflatedItemViewModel.updateChecked(inflatedItemViewModel.item.id, inflatedItemViewModel.item.checked)}&quot;
      tools:ignore=&quot;ContentDescription&quot; /&gt;
  </code></pre>
  <p>My <code>Checkbox</code> selector:</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  &lt;selector xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;&gt;
  
      &lt;item
          android:drawable=&quot;@drawable/ic_inflated_star_outline&quot;
          android:state_checked=&quot;false&quot;/&gt;
  
      &lt;item
          android:drawable=&quot;@drawable/ic_inflated_star_full&quot;
          android:state_checked=&quot;true&quot;/&gt;
  
      &lt;item
          android:drawable=&quot;@drawable/ic_inflated_star_outline&quot;/&gt;
  
  &lt;/selector&gt;
  </code></pre>
  <p>Other 2 buttons selector:</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  &lt;selector xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;&gt;
      &lt;item android:state_pressed=&quot;true&quot;&gt;
          &lt;shape&gt;
              &lt;solid android:color=&quot;@color/blue_200&quot;/&gt;
              &lt;corners android:radius=&quot;@dimen/_8sdp&quot;/&gt;
          &lt;/shape&gt;
      &lt;/item&gt;
  
      &lt;item android:state_pressed=&quot;false&quot;&gt;
          &lt;shape&gt;
              &lt;solid android:color=&quot;@color/blue_500&quot;/&gt;
              &lt;corners android:radius=&quot;@dimen/_8sdp&quot;/&gt;
          &lt;/shape&gt;
      &lt;/item&gt;
  &lt;/selector&gt;
  </code></pre>
  <p><strong>UPDATE 1: Suggested by Tenfour04</strong></p>
  <pre><code>&lt;com.google.android.material.button.MaterialButton
  android:id=&quot;@+id/btn_addtofavs&quot;
  android:layout_width=&quot;match_parent&quot;
  android:layout_height=&quot;match_parent&quot;
  android:layout_gravity=&quot;center&quot;
  android:background=&quot;@drawable/bg_button&quot;
  android:checkable=&quot;true&quot;
  android:checked=&quot;@={inflatedItemViewModel.item.checked}&quot;
  android:onClick=&quot;@{() -&gt; inflatedItemViewModel.updateChecked(inflatedItemViewModel.item.id, inflatedItemViewModel.item.checked)}&quot;
  app:icon=&quot;@drawable/inflated_selector_is_checked&quot;
  app:iconGravity=&quot;textStart&quot;
  app:iconPadding=&quot;0dp&quot;
  tools:ignore=&quot;ContentDescription&quot; /&gt;
  </code></pre>
  <p>Got an error:</p>
  <pre><code>Cannot find a getter for &lt;com.google.android.material.button.MaterialButton android:checked&gt; that accepts parameter type 'boolean' 
  </code></pre>
  <p>i.e it's not recognized by the Compiler as e two-stage button. Do I miss something?</p>