title: Shape Drawable parameters depending on applied style
body: <p>Let's say I have a simple shape drawable that draws a ring as follows:</p>
  
  <pre><code>&lt;shape xmlns:android="http://schemas.android.com/apk/res/android"
      android:dither="true"
      android:innerRadiusRatio="3"
      android:shape="ring"
      android:thicknessRatio="36"
      android:useLevel="false" &gt;
  
      &lt;gradient
          android:centerColor="@android:color/holo_blue_bright"
          android:centerY="0.001"
          android:endColor="@android:color/holo_blue_dark"
          android:gradientRadius="202.5"
          android:startColor="@android:color/transparent"
          android:type="radial"
          android:useLevel="false" /&gt;
  
  &lt;/shape&gt;
  </code></pre>
  
  <p>And I apply this shape as a view background as follows:</p>
  
  <pre><code>&lt;View
      android:layout_width="96dp"
      android:layout_height="96dp"
      android:padding="16dp"
      android:background="@drawable/custom_shape" /&gt;
  </code></pre>
  
  <p>The exact details of the shape are not relevant for this question - just suffice to say I have a shape. Now, I don't want to hard-code the various parameters for the shape. Let's take <code>thicknessRatio</code> as an example. If i wanted the thickness ratio to change depending on say, screen configuration, I'd of course use an integer resource as follows. I'd have a values.xml with the following:</p>
  
  <p><code>&lt;item name="thickness_ratio" type="integer" format="integer"&gt;56&lt;/item&gt;</code></p>
  
  <p>And then, <code>android:thicknessRatio="@integer/thickness_ratio"</code>.</p>
  
  <p>So far, so good. Now, I also want to have two "flavors" of my my shape drawable - a "large" one and a "small" one, and I wish to <strong>query the thickness ratio depending not on configuration, but on the style applied to the View</strong>. Which is what styles and themes are for. So, here's what I tried:</p>
  
  <h3>Step 1: Declare an attribute for thickness ratio (attrs.xml):</h3>
  
  <pre><code>&lt;resources&gt;
          &lt;attr name="thicknessRatio" format="reference" /&gt;
  &lt;/resources&gt;
  </code></pre>
  
  <h3>Step 2: Declare two styles utilizing this attribute (styles,xml):</h3>
  
  <pre><code>&lt;style name="CustomShapeSmall"&gt;
      &lt;item name="thicknessRatio"&gt;@integer/thickness_ratio_small&lt;/item&gt;
  &lt;/style&gt;
  
  &lt;style name="CustomShapeLarge"&gt;
      &lt;item name="thicknessRatio"&gt;@integer/thickness_ratio_large&lt;/item&gt;
  &lt;/style&gt;
  </code></pre>
  
  <h3>Step 3: Define the two integers in values.xml:</h3>
  
  <pre><code>&lt;item name="thickness_ratio_small" type="integer" format="integer"&gt;32&lt;/item&gt;
  &lt;item name="thickness_ratio_large" type="integer" format="integer"&gt;56&lt;/item&gt;
  </code></pre>
  
  <h3>Step 4: Query the custom attribute in the Shape Drawable:</h3>
  
  <p><code>android:thicknessRatio="?attr/thicknessRatio"</code></p>
  
  <h3>Step 5: Apply the desired style to the <code>View</code>:</h3>
  
  <pre><code>&lt;View
      android:layout_width="96dp"
      android:layout_height="96dp"
      android:padding="16dp"
      style="@style/CustomShapeSmall"
      android:background="@drawable/custom_shape" /&gt;
  </code></pre>
  
  <p>Unfortunately, this does not work. I get the following exception:</p>
  
  <pre><code>Caused by: android.content.res.Resources$NotFoundException: File res/drawable/custom_shape.xml from drawable resource ID #0x7f020000
      at android.content.res.Resources.loadDrawable(Resources.java:2091)
      at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
      at android.view.View.&lt;init&gt;(View.java:3364)
      at android.view.View.&lt;init&gt;(View.java:3293)
      ... 28 more
  Caused by: java.lang.NumberFormatException: Invalid float: "?2130771969"
      at java.lang.StringToReal.invalidReal(StringToReal.java:63)
      at java.lang.StringToReal.parseFloat(StringToReal.java:310)
      at java.lang.Float.parseFloat(Float.java:300)
      at android.content.res.TypedArray.getFloat(TypedArray.java:287)
      at android.graphics.drawable.GradientDrawable.inflate(GradientDrawable.java:827)
      at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:901)
      at android.graphics.drawable.Drawable.createFromXml(Drawable.java:837)
      at android.content.res.Resources.loadDrawable(Resources.java:2087)
  </code></pre>
  
  <p>From the exception stack trace, it appears that the line <code>android:thicknessRatio="?attr/thicknessRatio"</code>resolves to a question mark followed by the integer value of <code>R.attr.thicknessRatio</code> - however no further resolution is performed to actually query the value of this attribute.</p>
  
  <p>What am I missing here?</p>
  
  <hr>
  
  <h2>EDIT:</h2>
  
  <p><a href="https://github.com/curioustechizen/so-question-android-custom-styles">Here</a> is the complete github project for this issue.</p>