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>
Is this a bug or expected behavior?
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!