title: How to obtain a Drawable (with drawable alias) using TypedArray
body: <p>So, according to the Android documentation, <code>Resources.getDrawable()</code> has a known bug for OS versions before Jelly Bean, where aliased drawables would not be resolved with the correct density (so a 100px image in drawable-hdpi gets upscaled to 150px on an HDPI device):</p>
  
  <blockquote>
    <p>Note: Prior to JELLY_BEAN, this function would not correctly retrieve the final configuration density when the resource ID passed here is an alias to another Drawable resource. This means that if the density configuration of the alias resource is different than the actual resource, the density of the returned Drawable would be incorrect, resulting in bad scaling. To work around this, you can instead retrieve the Drawable through TypedArray.getDrawable. Use Context.obtainStyledAttributes with an array containing the resource ID of interest to create the TypedArray.</p>
  </blockquote>
  
  <p>However, I've not been able to actually resolve a <code>Drawable</code> using the instructions specified. A utility method that I've written:</p>
  
  <pre><code>@NonNull
  public static Drawable resolveDrawableAlias(@NonNull Context ctx, @DrawableRes int drawableResource) {
      final TypedArray a = ctx.obtainStyledAttributes(new int[] { drawableResource });
      final Drawable result = a.getDrawable(0);
      a.recycle();
      return result;
  }
  </code></pre>
  
  <p>always returns null when I'm passing in a resource ID for a drawable alias, which I've defined in <code>res/values/drawables.xml</code> as:</p>
  
  <pre><code>&lt;item name="my_drawable" type="drawable"&gt;@drawable/my_drawable_variation&lt;/item&gt;
  </code></pre>
  
  <p>Is there something I'm missing here, or some other workaround? </p>
  
  <p>EDIT: I've added a solution below.</p>