You may say this is duplicated but it's not. Actually I found solutions but none worked perfectly. Last solution was using TextInputLayout plus EditText inside it but is there a way to move the toggle button to other side of EditText? If not, so it's of no use for me.
<android.support.design.widget.TextInputLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="30dp" android:layout_marginRight="30dp" android:layout_marginTop="130dp" android:layoutDirection="rtl" app:passwordToggleEnabled="true"> <EditText android:id="@+id/edlrPassword" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="Password" android:paddingRight="10dp" android:paddingLeft="10dp" android:layoutDirection="rtl" android:textAlignment="viewStart" android:inputType="textPassword" android:maxLines="1" android:textSize="14sp" /> </android.support.design.widget.TextInputLayout> Again, problem is that the toggle button places on the EditText making part of it invisible.
I have tried these piece of code too:
if (b) editText.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD); else editText.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD | InputType.TYPE_CLASS_TEXT); Also I tried this code:
if (b) editText.setInputType(InputType.TYPE_CLASS_TEXT); else editText.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD); Both work for the first change, and then the text inside EditText remains visible all the time. What should I do? Any help is appreciated.
UPDATE: So I just noticed I needed to add android:layoutDirection="rtl" to the TextInputLayout! Previously I had added it to just editText, causing a conflict (as TextInputLayout was ltr by default) which made toggle button cover the editText. By the way when I put my editText inside a TextInputLayout, then setTransformationMethod(new PasswordTransformationMethod()) also works perfectly though I don't need it anymore!
Thank all for participation.