Is there really no XML attribute counterpart to setAlpha(int)
?
If not, what alternatives are there?
No, there is not, see how the "Related XML Attributes" section is missing in the ImageView.setAlpha(int) documentation. The alternative is to use View.setAlpha(float) whose XML counterpart is android:alpha
. It takes a range of 0.0 to 1.0 instead of 0 to 255. Use it e.g. like
<ImageView android:alpha="0.4">
However, the latter in available only since API level 11.
setAlpha(int)
is deprecated as of API 16
: Android 4.1
Please use setImageAlpha(int)
instead
I am not sure about the XML but you can do it by code in the following way.
ImageView myImageView = new ImageView(this);
myImageView.setAlpha(xxx);
In pre-API 11:
In API 11+: