There is no general way of getting the alpha value of a Drawable prior of API 19.
Anyway, according to what kind of Drawable you have, you can check the source code to deduct the alpha with a workaround.
For instance looking at the ColorDrawable source it's easy to see that you can port the implemention prior to Kitkat.
@Override
public int getAlpha() {
return mColorState.mUseColor >>> 24;
}
so drawable.getAlpha()
becomes drawble.getColor() >>> 24
EDIT:
here is a uncomplete attempt to make a compat method, i'll try to update this with time:
public static int getAlphaCompat( Drawable drawable ) {
if (VERSION.SDK_INT >= VERSION_CODES.KITKAT)
return drawable.getAlpha();
if( drawable instanceof ColorDrawable ) {
return ((ColorDrawable) drawable).getColor() >>> 24;
} else if( drawable instanceof BitmapDrawable ) {
return ((BitmapDrawable) drawable).getPaint().getAlpha();
} else if( drawable instanceof RotateDrawable ) {
return getAlphaCompat( ((RotateDrawable) drawable).getDrawable() );
} else if( drawable instanceof ScaleDrawable ) {
return getAlphaCompat( ((ScaleDrawable) drawable).getDrawable() );
} else if( drawable instanceof ClipDrawable ) {
//TODO: possible with reflection
} else if( drawable instanceof ShapeDrawable ) {
//TODO: possible with reflection
} else if( drawable instanceof DrawableContainer ) {
//TODO: possible with reflection
} else if( drawable instanceof GradientDrawable ) {
//TODO: possible with reflection
}
return -1;
}