Android and setting alpha for (image) view alpha


Question

Is there really no XML attribute counterpart to setAlpha(int)?

If not, what alternatives are there?

1
111
8/15/2015 10:48:46 AM

Accepted Answer

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.

162
11/9/2017 10:39:13 AM

It's easier than the other response. There is an xml value alpha that takes double values.

android:alpha="0.0" thats invisible

android:alpha="0.5" see-through

android:alpha="1.0" full visible

That's how it works.


Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon