I created alert dialog with TextInputLayout programmatically in fragment. I need to hide password by default, TextInputLayout has toggle button and it is working as expected hide/show on click. I tried to keep password hidden by default by settingsingleline to true and other hack i got from other SO answers but i still not able to get desired result. Any idea why i am not getting desired result?
TextInputLayout passwordParent = new TextInputLayout(getActivity());
passwordParent = new TextInputLayout(getActivity());
TextInputEditText passWord= new TextInputEditText(getActivity());
passWord.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD);
passWord.setBackgroundResource(R.drawable.background);
passWord.setBackgroundColor(getResources().getColor(R.color.white));
passwordParent.setEndIconMode(TextInputLayout.END_ICON_PASSWORD_TOGGLE);
passwordParent.setEndIconDrawable(R.drawable.show_password_selector);
passwordParent.addView(passWord);
Background XML Selector
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/ic_remove_red_eye_black_24dp" android:state_checked="true"/> // Visible Eye Icon
<item android:drawable="@drawable/ic_visibility_off_black_24dp"/> // Hide Eye Icon
</selector>
Edit: It's working by adding InputType.TYPE_CLASS_TEXT into input type like this passWord.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD | InputType.TYPE_CLASS_TEXT); but the icon still stay the same, its still showing wrong eye icon.
