title: How to extract color values (#rgb) from an Android theme?
body: <p>I want to use colors from a Theme to apply it to some HTML my app is rendering. I am wondering if I can do that?</p>
  
  <p>I am looking to use colors like they are specified in themes.xml:</p>
  
  <pre><code>    &lt;item name="colorBackground"&gt;@android:color/background_dark&lt;/item&gt;
      &lt;item name="textColorPrimary"&gt;@android:color/primary_text_dark&lt;/item&gt;
  </code></pre>
  
  <p>So looking at them they are declared in the same way. So I thought I could access them in the same way too.</p>
  
  <p>That is not the cause though. When trying to access those values this way:</p>
  
  <pre><code>    TypedValue tv = new TypedValue();
      getTheme().resolveAttribute(android.R.attr.colorBackground, tv, true);
  
      System.out.println("tv.string=" + tv.string);
      System.out.println("tv.coerced=" + tv.coerceToString());
  
      int colorResourceId = getResources().getColor(tv.resourceId);
      System.out.println("colorResourceId=" + colorResourceId);
  
      tv = new TypedValue();
      getTheme().resolveAttribute(android.R.attr.textColorPrimary, tv, true);
  
      System.out.println("tv.string=" + tv.string);
      System.out.println("tv.coerced=" + tv.coerceToString());
  
      colorResourceId = getResources().getColor(tv.resourceId);
      System.out.println("colorResourceId=" + colorResourceId);
  </code></pre>
  
  <p>I get this as a result:</p>
  
  <pre><code>I/System.out( 1578): tv.string=null
  I/System.out( 1578): tv.coerced=#ffffffff 
  I/System.out( 1578): colorResourceId=-1
  
  I/System.out( 1578): tv.string=res/color/primary_text_light.xml
  I/System.out( 1578): tv.coerced=res/color/primary_text_light.xml
  I/System.out( 1578): colorResourceId=-16777216
  </code></pre>
  
  <p>The results are different. The first one actually gives me the color "#fffffff" which would work for me, the second one only gives me an xml. </p>
  
  <p>Do I need to jump through a few more hoops here to resolve the actual color? Does my original intention work at all? Maybe it won't work, because colors could be arbitrary drawables?</p>
  
  <p>I didn't find any <i>relevant</i> documentation, but if you know any, just point me there please.</p>
  
  <p>Btw. I also tried obtainStyledAttributes(), but this had basically the same issues.</p>