Rakesh L
Rakesh L

Reputation: 1168

Android - How to Set a semi-transparent layout?

I'm new to android application. enter image description here

In this picture,there is a bottom layout with some options like play,delete etc.., and has its transparency to show its background.

How to I get like that ?

Upvotes: 19

Views: 46530

Answers (5)

ConcernedHobbit
ConcernedHobbit

Reputation: 874

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

Upvotes: 6

baronS
baronS

Reputation: 1084

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);

Upvotes: 57

thiagolr
thiagolr

Reputation: 7027

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

Upvotes: 17

David Jashi
David Jashi

Reputation: 4511

Use 32-bit PNG with transparency for your background (in that particular case, cause it does not have uniform transparency)

Upvotes: 1

Related Questions