Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - How to Set a semi-transparent layout?

Tags:

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 ?

like image 518
Rakesh L Avatar asked Jun 05 '13 10:06

Rakesh L


People also ask

How do you make a half background transparent?

Changing the opacity of the background color only To achieve this, use a color value which has an alpha channel—such as rgba. As with opacity , a value of 1 for the alpha channel value makes the color fully opaque. Therefore background-color: rgba(0,0,0,. 5); will set the background color to 50% opacity.


3 Answers

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);
like image 71
baronS Avatar answered Sep 22 '22 07:09

baronS


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

like image 21
thiagolr Avatar answered Sep 22 '22 07:09

thiagolr


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

like image 35
ConcernedHobbit Avatar answered Sep 21 '22 07:09

ConcernedHobbit