title: Why so complex to set style from code in Android
body: <p>If you want to set the style of a Button you create from code you have to do something like this;</p>
  
  <pre><code>Button  btn  = new Button (mActivity, null, R.attr.someattribute);
  </code></pre>
  
  <p>in attrs.xml, you set up a reference</p>
  
  <pre><code>&lt;attr name="someStyleRef" format="reference"/&gt;
  </code></pre>
  
  <p>In styles.xml, you define a theme</p>
  
  <pre><code>&lt;resources&gt;
    &lt;style name="Theme.SomeTheme" parent="android:style/Theme.Black"&gt;
       &lt;item name="someStyleRef"&gt;@style/someStyle&lt;/item&gt;
    &lt;/style&gt;
  &lt;/resources&gt;
  </code></pre>
  
  <p>That lates in styles.xml is defined as for example</p>
  
  <pre><code>&lt;style name="someStyle"&gt;
          &lt;item name="android:layout_width"&gt;2px&lt;/item&gt;
          &lt;item name="android:layout_height"&gt;fill_parent&lt;/item&gt;
          &lt;item name="android:background"&gt;@drawable/actionbar_compat_separator&lt;/item&gt;
   &lt;/style&gt;
  </code></pre>
  
  <p>This works, and this is, according to my understanding, the way to set a style on a View  from code in Android. This seems overly Complex. The button's third constructor Argument could easily have accepted a style ID R.style.XXX</p>
  
  <p>Can anyone explain why this extra complexity is needed? </p>