【问题标题】:Transparent EditText Android Studio透明的 EditText Android Studio
【发布时间】:2019-11-18 07:56:33
【问题描述】:

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

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

【问题讨论】:

  • 因为那不是透明的。完全透明不会有磨砂的外观。它的部分透明,alphaing 一些白色。您需要一个介于 FF 和 00 之间的 alpha 字节(可能更接近 00)。

标签: java android xml android-studio android-layout


【解决方案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>

更改&lt;solid android:color="#80ffffff" /&gt; 的颜色值以调整透明度。

【讨论】:

    【解决方案2】:

    添加background 属性来设置像这样的编辑文本背景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>
    

    【讨论】:

      【解决方案3】:

      如果你想调整透明度,你可以试试这个改变我给的颜色的alpha为#FF000000或#FFFFFFFF,你可以改变前2个字符(alpha)来改变透明度

      【讨论】:

        猜你喜欢
        • 2011-08-08
        • 2012-01-29
        • 2014-03-03
        • 1970-01-01
        • 1970-01-01
        • 2017-05-05
        • 2015-12-02
        • 2019-01-17
        • 1970-01-01
        相关资源
        最近更新 更多