Rikco
Rikco

Reputation: 33

My drawableLeft disappear if I use passwordToggleEnabled (EditText)

I'm trying to have beautiful EditText in my application and I would use DrawableLeft to add simple icon on each input. Everything is ok but on the EditText "Password", I added the passwordToggleEnabled (The user can see the input if he clicks on the eye). Adding this makes my drawableLeft disappear.

Have you and idea ? (Sorry for my poor english :-/)

Capture with drawable left

Capture with password eye

Here is my TextInputLayout :

<android.support.design.widget.TextInputLayout
    android:id="@+id/textInputPassword"
    android:layout_width="300dp"
    android:layout_height="60dp"
    android:layout_marginTop="16dp"
    android:theme="@style/EditTextHint"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/textInputEmail">

    <EditText
        android:id="@+id/editTextPassword"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:layout_marginTop="8dp"
        android:backgroundTint="@color/shapy_blue"
        android:drawablePadding="10dp"
        android:drawableStart="@mipmap/picto_password_blue"
        android:ems="10"
        android:hint="@string/enter_password"
        android:inputType="textPassword"
        android:textColor="@color/shapy_blue"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_bias="0.478"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.459" />

</android.support.design.widget.TextInputLayout>

Edit >> When I change the drawable color in Java, (on Focus listener)

@Override
public void onFocusChange(View view, boolean b) {
    if(view == editTextEmail){
        editTextEmail.setCompoundDrawablesWithIntrinsicBounds(R.mipmap.picto_mail_white,0,0,0);
        editTextEmail.setTextColor(getResources().getColor(R.color.white));
    } else {
        editTextEmail.setCompoundDrawablesWithIntrinsicBounds(R.mipmap.picto_mail_blue,0,0,0);
        editTextEmail.setTextColor(getResources().getColor(R.color.shapy_blue));
    }
    if(view == editTextPasswordLogin){
        editTextPasswordLogin.setCompoundDrawablesWithIntrinsicBounds(R.mipmap.picto_password_white,0,0,0);
        editTextPasswordLogin.setTextColor(getResources().getColor(R.color.white));
    } else {
        editTextPasswordLogin.setCompoundDrawablesWithIntrinsicBounds(R.mipmap.picto_password_blue,0,0,0);
        editTextPasswordLogin.setTextColor(getResources().getColor(R.color.shapy_blue));
    }

}

Upvotes: 3

Views: 2719

Answers (3)

Kuti Gbolahan
Kuti Gbolahan

Reputation: 2439

If you're still facing this issue, what fixed it for me was adding these lines to the inputlayout

app:endIconMode="password_toggle"
app:errorIconDrawable="@null"

Upvotes: 0

Jithu
Jithu

Reputation: 117

Use

android:drawableStart="@drawable/ic_password" 

in EditText with drawableLeft

This is my sample code

                    <android.support.design.widget.TextInputLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    app:passwordToggleDrawable="@drawable/show_password_selector"
                    app:passwordToggleEnabled="true"
                    android:orientation="vertical">
                    <android.support.v7.widget.AppCompatEditText
                        android:layout_width="180dp"
                        android:layout_height="wrap_content"
                        android:inputType="textPassword"
                        android:drawableLeft="@drawable/ic_password"
                        android:drawableStart="@drawable/ic_password"
                        android:hint="Password"/>
                </android.support.design.widget.TextInputLayout>

Upvotes: 10

Qandil Tariq
Qandil Tariq

Reputation: 539

app:passwordToggleDrawable - Drawable to use as the password input visibility toggle icon. I think due to its own drawable property its gone. Please set this drawable and check.

Upvotes: 1

Related Questions