Shailendra Pundhir
Shailendra Pundhir

Reputation: 121

Edittext field when using password input does not hide password

Edittext field in android when using password input does not hide password. It worked before but I am unable to figure out what went wrong or what changed. Here is the source code:

XML

<EditText
    android:id="@+id/login_password"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center_vertical"
    android:background="@drawable/rectangular_border_edittext"
    android:hint="@string/enter_password"
    android:inputType="textPassword"
    android:maxLines="1"
    android:padding="8dp" />

JAVA

   password.setSingleLine();
    password.setImeOptions(EditorInfo.IME_ACTION_NEXT);   password.setImeActionLabel(getResources().getString(R.string.goButton), EditorInfo.IME_ACTION_NEXT);
    password.setOnEditorActionListener((v, actionId, event) -> {
                if (actionId == EditorInfo.IME_ACTION_NEXT) {
                    checkPasswordAndSend();
                }
                return false;
            });

If somebody has encountered similiar problem before please let me know. Also I would like to tell you I am using latest version of support libraries.(25.3.1).

Upvotes: 3

Views: 154

Answers (2)

J&#233;w&#244;m&#39;
J&#233;w&#244;m&#39;

Reputation: 3971

Remove this line in your XML :

android:maxLines="1"

You should have this :

<EditText
android:id="@+id/login_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:background="@drawable/rectangular_border_edittext"
android:hint="@string/enter_password"
android:inputType="textPassword"
android:padding="8dp" />

And keep this line in your JAVA like in your example :

password.setSingleLine();

Upvotes: 2

Shailendra Pundhir
Shailendra Pundhir

Reputation: 121

So I figured it out. The maxlines attribute in password tends to this behaviour. Remove maxLines = 1 from xml and setSingleLine from java and everything goes back to normal. Dont know why this works, but just works. Hope this helps someone.

Upvotes: 3

Related Questions