title: Android: change background color View onClick Button
body: <p>How I can change the background color to a <code>View</code> this under a button when I click the <code>button</code>? I've tried a <code>selector</code> does not work because the View not change the color. What is the problem? </p>
  
  <p>This is my code:</p>
  
  <p><strong>XML</strong></p>
  
  <pre><code>    ...
            &lt;View
              android:id="@+id/viewPlanos2"
              android:layout_width="match_parent"
              android:layout_height="3dp"
              android:layout_gravity="center" /&gt;
  
          &lt;Button
              android:id="@+id/button"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:layout_gravity="center"
              android:layout_weight="1"
              android:background="@color/transparente"
              android:drawableTop="@drawable/buttonimage"
              android:gravity="center"
              android:paddingTop="50dp" /&gt;
  
          &lt;View
              android:id="@+id/viewPlanos1"
              android:layout_width="match_parent"
              android:layout_height="3dp"
              android:layout_gravity="center" /&gt;
   ...
  </code></pre>
  
  <p><strong>JAVA</strong></p>
  
  <pre><code>View linea2 = (View)findViewById(R.id.viewPlanos2);
  linea2.setBackgroundColor(getResources().getColor(R.drawable.linea_verde));
  </code></pre>
  
  <p><strong>linea_verde</strong></p>
  
  <p>
  </p>
  
  <pre><code>&lt;item android:state_pressed="true"&gt;&lt;shape&gt;
          &lt;gradient android:angle="90" android:endColor="@color/azul" android:startColor="@color/azulOscuro" /&gt;
      &lt;/shape&gt;&lt;/item&gt;
  &lt;item android:state_focused="true"&gt;&lt;shape&gt;
          &lt;gradient android:angle="90" android:endColor="@color/azul" android:startColor="@color/azulOscuro" /&gt;
      &lt;/shape&gt;&lt;/item&gt;
  &lt;item&gt;&lt;shape&gt;
          &lt;solid android:color="@color/rojo" /&gt;
      &lt;/shape&gt;&lt;/item&gt;
  </code></pre>
  
  <p></p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>I have tried:</p>
  
  <pre><code>public void onClick(View v) {
  
      if(v == botonMetro) {
  
          linea2.setBackgroundResource(R.drawable.linea_verde);
                      and
  
          linea2.setBackgroundColor(getResources().getColor(R.drawable.linea_verde));
      }
  }
  </code></pre>
  
  <p>But the code not work</p>