I have an xml file, res/color/btn_black that allows me to apply a gradient look to buttons.
I can use it in a layout.xml successfully by calling:
<Button
    android:background="@color/btn_black"
/>
Elsewhere, I am creating buttons dynamically in Java, and I want to apply the same style. When I try this using:
myButton.setBackgroundColor(getResources().getColor(R.color.btn_black));
I get this error:
android.content.res.Resources$NotFoundException: 
  File res/color/btn_black.xml from color state list resource ID #0x7f040001
This seems to be the correct method from other questions I've found answered here, but it isn't working for me. What am I doing wrong?
edit: This is the file btn_black.xml for reference
<selector xmlns:android="http://schemas.android.com/apk/res/android">
  <item android:state_pressed="true" >
    <shape>
        <solid
            android:color="#343434" />
        <stroke
            android:width="1dp"
            android:color="#171717" />
        <corners
            android:radius="3dp" />
        <padding
            android:left="10dp"
            android:top="10dp"
            android:right="10dp"
            android:bottom="10dp" />
    </shape>
  </item>
  <item>
    <shape>
        <gradient
            android:startColor="#343434"
            android:endColor="#171717"
            android:angle="270" />
        <stroke
            android:width="1dp"
            android:color="#171717" />
        <corners
            android:radius="4dp" />
        <padding
            android:left="10dp"
            android:top="10dp"
            android:right="10dp"
            android:bottom="10dp" />
    </shape>
  </item>
</selector>
 
     
     
    