1

When a TextInputLayout's app:passwordToggleEnabled attribute is set to true and a TextInputEditText's android:enabled attribute is set to false, how can one prevent the password toggle ImageButton from being clickable?

<com.google.android.material.textfield.TextInputLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="24dp"
    android:hint="@string/password"
    app:hintAnimationEnabled="true"
    app:passwordToggleEnabled="true">

    <com.google.android.material.textfield.TextInputEditText
        android:id="@+id/edit_text"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inputType="textPassword"
        android:maxLength="32"
        android:maxLines="1"
        android:enabled="false"/>

</com.google.android.material.textfield.TextInputLayout>

Issue demo

Is this a bug or expected behavior?

karel
  • 5,489
  • 46
  • 45
  • 50
papezjustin
  • 2,223
  • 6
  • 24
  • 31
  • 1
    I'm not sure but I think you should `setEnabled` of the TextInputLayout to `false` rather than the `TextInputEditText ` – Taslim Oseni Feb 23 '19 at 02:09
  • Crap. This was an oversight on my part. I had previously tried setting enabled via an xml attribute on TextInputLayout only to realize that it doesn't exist. I unfortunately did not then go back and check if there was a Java setter. Thank you for your help, your comment has resolved my issue. – papezjustin Feb 23 '19 at 02:34
  • Glad I could help :-) – Taslim Oseni Feb 23 '19 at 02:42

1 Answers1

1

Like I mentioned in the comments, a simple solution to your problem would be to setEnabled of the TextInputLayout to false rather than the TextInputEditText. Since the TextInputLayout houses the TextInputEditText, the entire layout would be disabled by this. Here's a little demo:

TextInputLayout textInputLayout = findViewById(R.id.textInputLayout);

if(someCondition){
    textInputLayout.setEnabled(false);
}

I hope this helps.. Merry coding!

Taslim Oseni
  • 6,086
  • 10
  • 44
  • 69