EditText设置背景不透明度
EditText set background opacity
要使 EditText
透明,我遇到了一些麻烦。这就是我要的 :
enter image description here
我试过了:
将背景应用于具有自定义形状的 editText:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" android:padding="10dp">
<solid android:color="@color/transparentButton"/>
<!-- this one is this color of the Rounded Button -->
<corners
android:bottomRightRadius="0dp"
android:bottomLeftRadius="0dp"
android:topLeftRadius="0dp"
android:topRightRadius="0dp"/>
</shape>`
<color name="transparentButton"> #4CFFFFFF </color>
<EditText
android:id="@+id/usernameLoginTxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableLeft="@drawable/ic_username_login"
android:drawablePadding="15dp"
android:background="@drawable/editetextbackground"
android:ems="10"
android:inputType="textPersonName"
android:hint="Username"
android:textColorHint="@color/black"
android:layout_marginLeft="8dp"
app:layout_constraintLeft_toLeftOf="@+id/titreLogin"
android:layout_marginRight="0dp"
app:layout_constraintRight_toRightOf="@+id/titreLogin"
android:layout_marginTop="44dp"
app:layout_constraintTop_toBottomOf="@+id/soustitrelogin"/>
但是如您所见,使用这种方法可以减小尺寸:
enter image description here
- 我也试过 setalpha,但都是透明的,编辑文本、图标和文本
感谢您的帮助,希望您能理解我。
试试这样将 android:padding="10dp"
添加到您的 EditText
中
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:hint="Nilesh Rathod"
android:drawablePadding="10dp"
android:layout_marginTop="10dp"
android:background="@drawable/edittext"
android:drawableLeft="@drawable/ic_cart" />
drawable/edittext 文件
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:padding="10dp"
android:shape="rectangle">
<solid android:color="#c0d7d0d0" /> <!-- this one is ths color of the Rounded Button -->
</shape>
要使 EditText
透明,我遇到了一些麻烦。这就是我要的 :
enter image description here
我试过了:
将背景应用于具有自定义形状的 editText:
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" android:padding="10dp"> <solid android:color="@color/transparentButton"/> <!-- this one is this color of the Rounded Button --> <corners android:bottomRightRadius="0dp" android:bottomLeftRadius="0dp" android:topLeftRadius="0dp" android:topRightRadius="0dp"/> </shape>` <color name="transparentButton"> #4CFFFFFF </color> <EditText android:id="@+id/usernameLoginTxt" android:layout_width="wrap_content" android:layout_height="wrap_content" android:drawableLeft="@drawable/ic_username_login" android:drawablePadding="15dp" android:background="@drawable/editetextbackground" android:ems="10" android:inputType="textPersonName" android:hint="Username" android:textColorHint="@color/black" android:layout_marginLeft="8dp" app:layout_constraintLeft_toLeftOf="@+id/titreLogin" android:layout_marginRight="0dp" app:layout_constraintRight_toRightOf="@+id/titreLogin" android:layout_marginTop="44dp" app:layout_constraintTop_toBottomOf="@+id/soustitrelogin"/>
但是如您所见,使用这种方法可以减小尺寸: enter image description here
- 我也试过 setalpha,但都是透明的,编辑文本、图标和文本
感谢您的帮助,希望您能理解我。
试试这样将 android:padding="10dp"
添加到您的 EditText
中
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:hint="Nilesh Rathod"
android:drawablePadding="10dp"
android:layout_marginTop="10dp"
android:background="@drawable/edittext"
android:drawableLeft="@drawable/ic_cart" />
drawable/edittext 文件
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:padding="10dp"
android:shape="rectangle">
<solid android:color="#c0d7d0d0" /> <!-- this one is ths color of the Rounded Button -->
</shape>