我正在尝试使我的android studio项目中的EditText
透明。我希望它看起来像这里的
但是,即使我尝试使用transparent
和ffffff
,我的情况也不是这样吗?有人可以帮我吗?我希望我的编辑文本背景看起来像我显示的图像中的背景。
答案 0 :(得分:1)
<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" />
的颜色值以调整透明度。
答案 1 :(得分:0)
添加background
属性以设置android:background="@drawable/edit_bg"
这样的edittext背景
尝试此代码
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>