[英]Transparent EditText Android Studio
<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" />
drawables文件夾中的edittext_bg.xml:
<?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>
更改<solid android:color="#80ffffff" />
顏色值以調整透明度。
添加background
屬性以設置edittext背景,例如android:background="@drawable/edit_bg"
試試這個代碼
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>
如果你想調整透明度改變我給的顏色的alpha,你可以這樣嘗試#FF000000 OR #FFFFFFFF,你可以改變前2個字符(alpha)來改變透明度
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.