2

I have an EditText to enter the password and i set inputType as "textPassword". But when i run it in app or emulator the password is visible. Why it is showing password instead of dots?

<EditText
 android:id="@+id/etPassword"
 android:layout_width="match_parent"
 android:inputType="textPassword"
 android:layout_height="wrap_content"
 android:hint="@string/Password"
 android:layout_marginBottom="10dp"
 android:maxLength="15"
 android:background="@drawable/ss"/>

drawable file ss:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<corners android:radius="10dp"/>
<padding android:left="10dp" android:right="10dp" android:top="10dp" android:bottom="10dp"/>
<solid android:color="#ffffffff"/>
<stroke android:width="1dp" android:color="#CCCCCC" />

Complete Layout:

  <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:padding="10dp"
        android:orientation="vertical"
        android:layout_height="match_parent"
        android:background="#ffffffff"
        android:gravity="center_vertical" >

        <ImageView
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:src="@drawable/foodstall"
         android:layout_gravity="center"
         android:layout_marginBottom="10dp"/>

        <LinearLayout
         android:layout_width="match_parent"
         android:orientation="vertical"
         android:layout_height="wrap_content"
         android:background="#ffffffff">

        <EditText
        android:id="@+id/etUsername"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="@string/Username"
        android:maxLength="15"
        android:background="@drawable/ss"
        android:layout_marginBottom="10dp"/>

        <EditText
        android:id="@+id/etPassword"
        android:layout_width="match_parent"
        android:inputType="textPassword"
        android:layout_height="wrap_content"                                                     android:hint="@string/Password"
        android:layout_marginBottom="10dp"
        android:maxLength="15"
        android:background="@drawable/ss"
                android:text="askdjhkashdjasdksakdkaskdhkashkdhkashdkjhakshdkjhaskhdkj"/>

        <Button
        android:id="@+id/bLogin"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/title_activity_login"
        android:background="@color/button"
        android:textColor="#ffffffff"
        android:layout_weight="1" />

        </LinearLayout>

        <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/linearlayout"
        android:background="@drawable/ss"
        android:layout_marginTop="10dp">

        <TextView
        android:id="@+id/tvRegisterLink"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:text="@string/Newuser"
        android:gravity="center"
        android:layout_weight="1"
        android:textStyle="bold"/>

        <TextView
        android:id="@+id/fpass"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:text="@string/title_activity_forgotpass"
        android:layout_weight="1"
        android:gravity="center"
        android:textStyle="bold"/>

        </LinearLayout>

        </LinearLayout>
user2269164
  • 1,095
  • 2
  • 15
  • 31

4 Answers4

5

1) Remove android:inputType="textPassword" from your xml file and instead, in set it in java:

  EditText password = (EditText) findViewById(R.id.password_text);
  password.setTransformationMethod(new PasswordTransformationMethod());

With this approach, the hint font looks good but as you're typing in that edit field, you don't see each character in plain text before it turns into a password dot. Also when making input in fullscreen, the dots will not appear, but the passoword in clear text.

2) Leave android:inputType="textPassword" in your xml. In Java,passwordMethod:

  EditText password = (EditText) findViewById(R.id.register_password_text);
  password.setTransformationMethod(new PasswordTransformationMethod());

This approach gave password dots.

Keyur Thumar
  • 608
  • 7
  • 19
2

Try adding android:password="true" in EditText. It should work.

    <EditText
      android:id="@+id/etPassword"
      android:layout_width="match_parent"
      android:inputType="textPassword"
      android:password="true"
      android:layout_height="wrap_content"
      android:hint="@string/Password"
      android:layout_marginBottom="10dp"
      android:maxLength="15"
      android:background="@drawable/ss"/>
Amey Haldankar
  • 2,223
  • 1
  • 24
  • 22
0

I also encountered this issue what work for me is:

I added this xml property to my EditText and it works fine:

android:singleLine="true"

I know its deprecated, but android:maxLines="1" not working although its the replacement for singleLine.

Arsal Imam
  • 2,882
  • 2
  • 24
  • 35
0

I have tested this is working fine

 <EditText
        android:id="@+id/etPassword"
        android:layout_width="match_parent"
        android:inputType="textWebPassword"
        android:layout_height="40dp"
        android:hint="Password"
        android:layout_marginBottom="10dp"
        android:maxLength="15" />

change your inputType from

android:inputType="textPassword"

to

android:inputType="textWebPassword"
Akp
  • 259
  • 1
  • 9