Наконец-то все получилось!
Я не нашел способа сделать это, установив изображение в XML, поэтому нужно установить его в коде.Вот что я получил, что работает:
Button btnObjects = (Button)this.findViewById(R.id.button_objects);
Bitmap bm = BitmapFactory.decodeResource(context.getResources(), R.drawable.button_image_objects);
if( <button needs to be disabled> )
{
btnObjects.setEnabled(false);
bm = adjustOpacity(bm, 128);
}
else
{
btnObjects.setEnabled(true);
}
btnObjects.setCompoundDrawablesWithIntrinsicBounds(null, new BitmapDrawable(bm), null, null);
//and here's where the magic happens
private Bitmap adjustOpacity(Bitmap bitmap, int opacity)
{
//make sure bitmap is mutable (copy of needed)
Bitmap mutableBitmap = bitmap.isMutable()
? bitmap
: bitmap.copy(Bitmap.Config.ARGB_8888, true);
//draw the bitmap into a canvas
Canvas canvas = new Canvas(mutableBitmap);
//create a color with the specified opacity
int colour = (opacity & 0xFF) << 24;
//draw the colour over the bitmap using PorterDuff mode DST_IN
canvas.drawColor(colour, PorterDuff.Mode.DST_IN);
//now return the adjusted bitmap
return mutableBitmap;
}