Edittext field when using enter password does not hide password

Edittext field in android when using password input does not hide password. This used to work, but I can't figure out what went wrong or what changed. Here's 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 anyone has encountered a similar issue before, please let me know. Also I would like to tell you that I am using the latest support libraries (25.3.1).

+3


source to share


2 answers


So I figured it out. The maxlines attribute in a password tends to behave like this. Remove maxLines = 1 from xml and setSingleLine from java and everything is back to normal. Not sure why this works, but it just works. Hope this helps someone.



+3


source


Remove this line in XML :

android:maxLines="1"

      

You should have something like 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 store this line in JAVA like in your example:

password.setSingleLine();

      

+2


source







All Articles