How to Change Linear Layout Transparency

Asked

Viewed 370 times

2

I have a login screen that has a LinearLayout blue background tranparente. How can I do 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>

2 answers

5


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

See this list where you have the list of transparencies:

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 that way:

android:background="#800000FF"

The 0000FF is related to blue, and the 80 in front indicates the 50% of transparency

  • 1

    Oops, I didn’t see that you had answered. Good answer! Here’s my +1

1

Instead of:

android:background="@color/colorPrimary"

Place:

android:background="#CC000000"

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

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

See below for an example of another percentage of transparency:

0%   -> #00 
25%  -> #40
50%  -> #80
75%  -> #C0
100% -> #FF
  • Friend is that the color needs to be this but it needs to be transparent because it will have an image behind...

  • Help me.......

  • 1

    @You have to go to @color/colorPrimary and see what is the hexadecimal of it. Then just insert in the front in place of the black I put =D

  • 1

    I understood friend. Thank you... But the other answer I found simpler to understand immediately... Oo...

  • 1

    @Aline No problem! I voted in the other answer also for being well explained. Good luck there. = D

  • Valeu amigo... D

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.