Android support library added TextInputLayout adding several features like floating label and password toggle visisbilty
My problem is How to customize passwordVisisbilityDrawable so my own icons for visible and hidden state will be displayed.
Also when I enable passwordToggleVisibility, height will increase.
There are five XML attributes associated with the password visibility toggle. passwordToggleEnabled: This attribute has its value either true or false, so when we want the password to be toggleable, we should assign this attribute the true value. passwordToggleTint: allows giving the color the visibility toggle icon.
app:passwordToggleDrawable - Drawable to use as the password input visibility toggle icon. app:passwordToggleTint - Icon to use for the password input visibility toggle. app:passwordToggleTintMode - Blending mode used to apply the background tint. More details in TextInputLayout documentation.
for change drawable, create a selector like below
password_toggle_drawable.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/ic_password_visible" android:state_checked="true"/>
<item android:drawable="@drawable/ic_password_hidden"/>
</selector>
then assign to TextInputLayout like below:
<android.support.design.widget.TextInputLayout
android:id="@+id/PasswordLayout"
xmlns:android="http://schemas.android.com/apk/res/android"
app:passwordToggleEnabled="true"
**app:passwordToggleDrawable="@drawable/password_toggle_drawable"**
xmlns:app="http://schemas.android.com/apk/res-auto">
<android.support.design.widget.CommonTextInputEditText
android:id="@+id/PasswordEditText"
android:padding="0dp"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"/>
</android.support.design.widget.TextInputLayout>
for height, I used below code after inflating:
CheckableImageButton text_input_password_toggle = (CheckableImageButton) PasswordLayout().findViewById(android.support.design.R.id.text_input_password_toggle);
text_input_password_toggle.setMinimumHeight(0);
PasswordEditText().setMinHeight(0);
PasswordEditText().setMinimumHeight(0);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With