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.
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. likeHowever, the latter in available only since API level 11.
Maybe a helpful alternative for a plain-colored background:
Put a LinearLayout over the ImageView and use the LinearLayout as a opacity filter. In the following a small example with a black background:
Vary the android:background attribute of the LinearLayout between #00000000 (fully transparent) and #FF000000 (fully opaque).
The alpha can be set along with the color using the following hex format #ARGB or #AARRGGBB. See http://developer.android.com/guide/topics/resources/color-list-resource.html
I am not sure about the XML but you can do it by code in the following way.
In pre-API 11:
In API 11+:
It's easier than the other response. There is an xml value
alpha
that takes double values.android:alpha="0.0"
thats invisibleandroid:alpha="0.5"
see-throughandroid:alpha="1.0"
full visibleThat's how it works.
setAlpha(int)
is deprecated as of API16
:Android 4.1
Please use
setImageAlpha(int)
instead