title: Android custom view background selection
body: <p>I have a custom view:</p>
  
  <pre><code>public class MyView extends RelativeLayout {
  
      private LayoutInflater inflater;
  
      public MyView(Context context, AttributeSet attrs) {
          super(context, attrs);
          inflater = LayoutInflater.from(context);
          inflater.inflate(R.layout.my_view, this);
      }
  }
  </code></pre>
  
  <p>with an xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"/&gt;
  </code></pre>
  
  <p>I also have a selector for the background:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;selector xmlns:android="http://schemas.android.com/apk/res/android"&gt;
       &lt;item android:state_pressed="true"
             android:drawable="@drawable/top_press" /&gt; &lt;!-- pressed --&gt;
       &lt;item android:drawable="@drawable/top_idle" /&gt; &lt;!-- default --&gt;
   &lt;/selector&gt;
  </code></pre>
  
  <p>When I use the selector as a background it doesn't work:</p>
  
  <pre><code>&lt;com.example.MyView style="@style/someStyle" 
      android:background="@drawable/item_selector_top" android:clickable="true"/&gt;
  </code></pre>
  
  <p>However, when I put the background from the internal xml it does work:</p>
  
  <pre><code>    &lt;?xml version="1.0" encoding="utf-8"?&gt;
      &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
  android:background="@drawable/item_selector_top"/&gt;
  </code></pre>
  
  <p>Does anyone know why?</p>