title: Android how to set background color on a Button
body: <p>I am trying to change the background color of a Button. I'm in Kotlin on SDK 21 on emulator.</p>
  
  <p>A View and a Button are declared in the layout XML file</p>
  
  <pre><code>&lt;View
      android:id="@+id/myview"
      android:layout_width="64dp"
      android:layout_height="32dp"
      /&gt;
  &lt;Button
      android:id="@+id/showButton"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="12dp"
      android:text="test"
      /&gt;
  </code></pre>
  
  <p>The API to set the color doesn't seem to work:</p>
  
  <pre><code>    showButton.setBackgroundColor(0xff60a0e0.toInt()) &lt;-- doesnt work
  </code></pre>
  
  <p>What works is:</p>
  
  <pre><code>    myview.setBackgroundColor(0xff60a0e0.toInt()) &lt;-- works, exact background color
      showButton.setTextColor(0xff000050.toInt()) &lt;-- works, exact text color
  </code></pre>
  
  <p>After trying further it seems that I can only set the alpha channel of the button, not the color:</p>
  
  <pre><code>    setBackgroundColor( 0xff000000.toInt())  &lt;-- works, opaque
      setBackgroundColor( 0x00000000.toInt())  &lt;-- works, transparent
  </code></pre>
  
  <p>Also same thing with:</p>
  
  <pre><code>        showButton.setBackgroundColor(Color.GREEN) &lt;-- doesnt work, button is opaque but not green
          showButton.setBackgroundColor(Color.TRANSPARENT) &lt;-- works, button is transparent
  </code></pre>
  
  <p>Any idea? Did I miss something in the other answers or the documentation?</p>
  
  <p>Here is complete layout, it used to inflate a fragment, if that matters:</p>
  
  <pre><code>
  
      &lt;?xml version="1.0" encoding="utf-8"?&gt;
       &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          xmlns:app="http://schemas.android.com/apk/res-auto"
          android:orientation="vertical"&gt;
          &lt;LinearLayout
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:orientation="horizontal"&gt;
             &lt;View
                 android:id="@+id/myview"
                 android:layout_width="64dp"
                 android:layout_height="32dp"
                /&gt;
             &lt;Button
                 android:id="@+id/showButton"
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:text="12dp"
                 android:text="test"
                 /&gt;
          &lt;/LinearLayout&gt;
          &lt;androidx.recyclerview.widget.RecyclerView
              android:id="@+id/dictionaryEntryRecyclerView"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:scrollbars="vertical"
              app:layoutManager="LinearLayoutManager"
              /&gt;
         &lt;/LinearLayout&gt;
  
  </code></pre>