Android - How to Set a semi-transparent layout?

The color format is ARGB, which means ALPHA/RED/GREEN/BLUE.

The transparency is set on the alpha channel, a value of 0 (0x00) is completely transparent and a value of 255 (0xFF) is completely opaque.

So if you need a grayish color half transparent, then set this color: #80444444


use android:background ="#88676767" change the first 88 to your selection of opacity

In reply to your comment:

ImageView iv = (ImageView) findViewById(your_imageId);    
iv.setColorFilter(Color.argb(150, 155, 155, 155),   Mode.SRC_ATOP);

Third option:

LinearLayout layout = (LinearLayout) findViewById(R.id.your_id);
    Drawable d = getResources().getDrawable(R.relevant_drawable);
    d.setAlpha(50);
    layout.setBackgroundDrawable(d);

It's also incredibly easy to just set the alpha value, one of two ways. My example applies a 60% opaque black background to a linear layout.

The first method is to add the following line to change the alpha of the layout in the XML file (also in image):

android:background="@android:color/black"
android:alpha="0.6"

XML File Method

The second method is to change the alpha and background values in the design editor view:

Design Editor Method

Tags:

Java

Android