Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Edittext field when using password input does not hide password

Tags:

java

android

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).

like image 943
Shailendra Pundhir Avatar asked Aug 28 '26 15:08

Shailendra Pundhir


2 Answers

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.

like image 62
Shailendra Pundhir Avatar answered Aug 31 '26 04:08

Shailendra Pundhir


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();
like image 21
Jéwôm' Avatar answered Aug 31 '26 04:08

Jéwôm'