简体   繁体   中英

Transparent EditText Android Studio

I am trying to make my EditText in my android studio project transparent. I want it to look like the EditText here

But mine doesn't look like that even though I have tried using transparent and ffffff can someone please help me with this? I want my edit text background to look like the one in the image I showed.

<EditText
        android:layout_width="match_parent"
        android:layout_margin="32dp"
        android:layout_height="wrap_content"
        android:hint="Username"
        android:padding="16dp"
        android:background="@drawable/edittext_bg" />

edittext_bg.xml in drawables folder:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <solid android:color="#80ffffff" />
    <corners android:radius="5dp" />
</shape>

Change color value of <solid android:color="#80ffffff" /> to adjust transparency.

Add background attribute to set edittext background like this android:background="@drawable/edit_bg"

try this code

edit_bg.xml

<?xml version="1.0" encoding="utf-8"?>
<shape android:shape="rectangle"
xmlns:android="http://schemas.android.com/apk/res/android">
<solid
    android:color="#E288CB"/>
<corners
    android:radius="5dp"/>

activity_main.xml

<?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:background="#C71D8B"
android:gravity="center"
tools:context=".TransparentEditActivtiy">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginLeft="40dp"
    android:layout_marginRight="40dp"
    android:orientation="vertical">


    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/edit_bg"
        android:hint="Enter Name"
        android:padding="15dp"
        android:textColor="#fff"
        android:textColorHint="#fff" />

    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/edit_bg"
        android:hint="Enter Password"
        android:padding="15dp"
        android:textColor="#fff"
        android:textColorHint="#fff"
        android:layout_marginTop="20dp"/>
</LinearLayout>

屏幕截图

You can try like this if you want to adjust the transparent change the alpha in color I gave as #FF000000 OR #FFFFFFFF, and you can change the first 2 caracters (alpha) to change degre of transparence

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM