title: Creating default values for custom attributes using styles and themes
body: <p>I have several custom <code>View</code>s in which I have created custom styleable attributes that are declared in xml layout and read in during the view's constructor.  My question is, if I do not give explicit values to all of the custom attributes when defining my layout in xml, how can I use styles and themes to have a default value that will be passed to my <code>View</code>'s constructor?</p>
  
  <p>For example:</p>
  
  <p>attrs.xml:</p>
  
  <pre><code>&lt;declare-styleable name="MyCustomView"&gt;
      &lt;attr name="customAttribute" format="float" /&gt;
  &lt;/declare-styleable&gt;
  </code></pre>
  
  <p>layout.xml (<code>android:</code> tags eliminated for simplicity):</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res/com.mypackage" &gt;
  
      &lt;-- Custom attribute defined, get 0.2 passed to constructor --&gt;
  
      &lt;com.mypackage.MyCustomView
          app:customAttribute="0.2" /&gt;
  
      &lt;-- Custom attribute not defined, get a default (say 0.4) passed to constructor --&gt;
  
      &lt;com.mypackage.MyCustomView /&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>