title: How can I define the size of the drawables in the style file?
body: <p>I would like to specify just once in <strong>res/values/styles.xml</strong> the size of two checkboxes and their four shape drawables</p>
  
  <ol>
  <li><strong>res/drawable/cb1_checked.xml</strong></li>
  <li><strong>res/drawable/cb1_unchecked.xml</strong></li>
  <li><strong>res/drawable/cb2_checked.xml</strong></li>
  <li><strong>res/drawable/cb2_unchecked.xml</strong>.</li>
  </ol>
  
  <p>This way the size would appear one time in the style rather than four in the drawables.</p>
  
  <p>Neither of the two attempts below work. Can you suggest a solution? (If you see what's wrong with these two attempts, please do mention it.)</p>
  
  <p>----------------------------------------------------------------<strong>Attempt 1</strong>----------------------------------------------------------------</p>
  
  <p>Replace</p>
  
  <p><strong>res/drawable/cb1_checked.xml</strong></p>
  
  <pre><code>&lt;size android:width="24dp"
        android:height="24dp" /&gt;
  </code></pre>
  
  <p>with</p>
  
  <p><strong>res/values/styles.xml</strong></p>
  
  <pre><code>&lt;item name="android:layout_width"&gt;24dp&lt;/item&gt;
  &lt;item name="android:layout_height"&gt;24dp&lt;/item&gt;
  </code></pre>
  
  <p>----------------------------------------------------------------<strong>Attempt 2</strong>----------------------------------------------------------------</p>
  
  <p>Add</p>
  
  <p><strong>res/values/styles.xml</strong></p>
  
  <pre><code>&lt;item name="android:background"&gt;cb_background&lt;/item&gt;
  </code></pre>
  
  <p>and define a background drawable</p>
  
  <p><strong>res/drawable/cb_background.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;shape xmlns:android="http://schemas.android.com/apk/res/android"
      android:shape="rectangle"&gt;
      &lt;solid android:color="#00FF00"/&gt;
      &lt;size android:width="24dp"
            android:height="24dp" /&gt;
  &lt;/shape&gt;
  </code></pre>
  
  <p>----------------------------------------------------------------<strong>Added</strong>----------------------------------------------------------------</p>
  
  <p>Here is the full set of XML files:</p>
  
  <p><strong>res/layout/activity_main.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:id="@+id/MyLL"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"&gt;
  
      &lt;CheckBox
          android:id="@+id/cb1"
          style="@style/CB_style"
          android:button="@drawable/cb1_selector"
          android:height="@dimen/my24sp" /&gt;
  
      &lt;CheckBox
          android:id="@+id/cb2"
          style="@style/CB_style"
          android:button="@drawable/cb2_selector"
          android:height="@dimen/my24sp" /&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p><strong>res/values/styles.xml</strong></p>
  
  <p></p>
  
  <pre><code>&lt;style name="AppBaseTheme" parent="android:Theme.Light"&gt;
  &lt;/style&gt;
  
  &lt;style name="AppTheme" parent="AppBaseTheme"&gt;
  &lt;/style&gt;
  
  &lt;style name="CB_style" parent="@android:style/TextAppearance.Medium"&gt;
      &lt;item name="android:layout_width"&gt;wrap_content&lt;/item&gt;
      &lt;item name="android:layout_height"&gt;wrap_content&lt;/item&gt;
      &lt;item name="android:layout_weight"&gt;1&lt;/item&gt;
      &lt;item name="android:layout_gravity"&gt;center_horizontal&lt;/item&gt;
      &lt;item name="android:gravity"&gt;center&lt;/item&gt;
      &lt;item name="android:checked"&gt;false&lt;/item&gt;
  &lt;/style&gt;
  </code></pre>
  
  <p></p>
  
  <p><strong>res/drawable/cb1_selector.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;selector xmlns:android="http://schemas.android.com/apk/res/android"
            android:constantSize="true"&gt;
  
      &lt;item android:state_checked="true"
            android:drawable="@drawable/cb1_checked" /&gt;
  
      &lt;item android:state_checked="false"
            android:drawable="@drawable/cb1_unchecked" /&gt;
  
  &lt;/selector&gt;
  </code></pre>
  
  <p><strong>res/drawable/cb1_checked.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;shape xmlns:android="http://schemas.android.com/apk/res/android"
      android:shape="rectangle"&gt;
      &lt;solid android:color="#FF0000"/&gt;
      &lt;size android:width="24dp"
            android:height="24dp" /&gt;
  &lt;/shape&gt;
  </code></pre>
  
  <p><strong>res/drawable/cb1_unchecked.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;shape xmlns:android="http://schemas.android.com/apk/res/android"
      android:shape="rectangle"&gt;
      &lt;solid android:color="#880000"/&gt;
      &lt;size android:width="24dp"
            android:height="24dp" /&gt;
  &lt;/shape&gt;
  </code></pre>
  
  <p>(and similarly for the cb2 selector and checked/unchecked drawables)</p>