繁体   English   中英

透明EditText Android工作室

[英]Transparent EditText Android Studio

我正在尝试使我的 android 工作室项目中的EditText透明。 我希望它看起来像这里的 EditText

但是我的看起来不像那样,即使我尝试使用transparentffffff有人可以帮我解决这个问题吗? 我希望我的编辑文本背景看起来像我显示的图像中的背景。

<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.

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