Changing Linear Layout Transparency

2

I have a login screen that has a LinearLayout with transparent blue background. How can I make this LinearLayout with id be translucent?

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.teste.testenotification.MainActivity">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="100dp">

 <ImageView
    android:id="@+id/imageView2"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:srcCompat="@mipmap/ic_launcher" />
</LinearLayout>



<LinearLayout
    android:id="@+id/corTransparente"
    android:layout_margin="20dp"
    android:orientation="vertical"
    android:background="@color/colorPrimary"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <LinearLayout
        android:padding="20dp"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <EditText

            android:drawablePadding="10dp"
            android:drawableLeft="@mipmap/ic_launcher"
            android:id="@+id/editText2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:inputType="textPersonName"
            android:hint="Usuario"
            />

        <EditText
            android:drawablePadding="10dp"
            android:drawableLeft="@drawable/login"
            android:hint="Senha"
            android:id="@+id/editText"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:inputType="textPersonName"
            />
        <Button
            android:id="@+id/button"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Button" />
    </LinearLayout>


</LinearLayout>

    
asked by anonymous 29.08.2017 / 22:34

2 answers

5

You can put a transparency on the background color, instead of using colorPrimary

See this list where the transparency list is:

100% — FF
95% — F2
90% — E6
85% — D9
80% — CC
75% — BF
70% — B3
65% — A6
60% — 99
55% — 8C
50% — 80
45% — 73
40% — 66
35% — 59
30% — 4D
25% — 40
20% — 33
15% — 26
10% — 1A
5% — 0D
0% — 00

So for example, if you want to put a blue background with 50% transparency, it would look like this:

android:background="#800000FF"

0000FF is blue, and 80 at the front indicates 50% transparency

    
29.08.2017 / 22:41
1

Instead of:

android:background="@color/colorPrimary"

Place:

android:background="#CC000000"

This is a black hexadecimal with 80% transparency. To put transparency, just set the first two digits of a hexadecimal.

[CC][000000] ----> Cor
  |     
  +--> Transparência

Below is an example of another percentage of transparency:

0%   -> #00 
25%  -> #40
50%  -> #80
75%  -> #C0
100% -> #FF
    
29.08.2017 / 22:44