39

I have an EditText field which needs to be a numeric password field. Everything works OK in portrait mode; not in landscape. When the user selects the EditText field, the UI zooms into the field and when I type all the characters are visible.

I need a numeric keyboard also. I tried setting the input type to text password|number. If I remove "number" option everything works right; otherwise no.

Any suggestions?

teedyay
  • 23,293
  • 19
  • 66
  • 73
  • See the Answer : [http://stackoverflow.com/questions/15257058/how-to-show-numeric-soft-keyboard-for-password-field-in-android](http://stackoverflow.com/questions/15257058/how-to-show-numeric-soft-keyboard-for-password-field-in-android) – Mohammed Akdim Oct 06 '15 at 10:37

8 Answers8

61

This problem can be solved without using deprecated android:password. Use the following code snippet, but do not reverse the sequence of calls:

    EditText editText = (EditText) findViewById(R.id.MyEditText);
    editText.setInputType(InputType.TYPE_CLASS_NUMBER);
    editText.setTransformationMethod(PasswordTransformationMethod.getInstance());
Viktor Brešan
  • 5,293
  • 5
  • 33
  • 36
  • 1
    Sure, but somehow not as clear as a simple android:password="true". I wonder why they deprecated it. – ettore Mar 08 '11 at 02:58
  • 5
    Somehow this does not seem to work on 2.3.x . Turning to landscape the passwort is still visible as described by Mar. – Marcus Wolschon Aug 29 '11 at 09:45
  • I just found out that `editText.setSingleLine(true);` after the `editText.setTransformationMethod()` causes the dots to stop being shown !! – Someone Somewhere Jan 05 '12 at 21:52
18

The simplest solution that I found for a numeric text entry that needed to be hidden (password style) was to use: android:inputType="numberPassword"

Full example that worked for me:

<EditText
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    style="@style/MyLargeTextBox"
    android:background="@android:drawable/editbox_background_normal"
    android:id="@+id/txtWebServicePIN"
    android:layout_row="3"
    android:layout_column="2"
    android:layout_columnSpan="2"
    android:minWidth="100dp"
    android:maxWidth="100dp"
    android:inputType="numberPassword"
    android:maxLength="6"/>
robnick
  • 1,720
  • 17
  • 27
6

To fix the issue where the password is visible in the landscape mode full-screen editor (as Marcus described), you can add the following line to disable the full-screen editor:

editText.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI);

You may also want to change the typeface to monospace to better emulate the text-password behavior:

editText.setTypeface(Typeface.MONOSPACE);
Adam L.
  • 394
  • 6
  • 10
3

Using the deprecated

android:password="true"

may solve your problem.

Diego Torres Milano
  • 65,697
  • 9
  • 111
  • 134
  • Indeed, I was about to link to your previous answer: http://stackoverflow.com/questions/2017674/edittext-set-for-password-with-phone-number-input-android/2017791#2017791 – Christopher Orr Mar 10 '10 at 23:47
1

Try this in XML & nothing changes in manifest file,

<EditText
         android:id="@+id/etPassword"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:inputType="textPassword"
         android:singleLine="true" />
pradip
  • 185
  • 1
  • 3
  • 11
0

This how to make input password that has hint which not converted to * !!.

On XML :

android:inputType="textPassword"
android:gravity="center"
android:ellipsize="start"
android:hint="Input Password !."

thanks to : mango and rjrjr for the insight :D.

Bhimbim
  • 1,348
  • 2
  • 19
  • 15
0

Try with this:

EditText input = (EditText) findViewById(R.id.input);
input.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_VARIATION_PASSWORD);

More info HERE

atiruz
  • 2,782
  • 27
  • 36
-2

I think you should use android:password="true" and android:numeric="integer". But as the Android documentation states (in R.attr.html, not in the TextView docs), these are deprectated and you should use android:inputType. inputType takes flag, so you can mix mulitple possibilities. And I think android:inputType="number | password" should work for you.

You should specify android:password="true" if you want to support older devices too.

MrSnowflake
  • 4,724
  • 3
  • 29
  • 32
  • See dtmilano's answer, plus the link I gave to a previous question which covers these points. Unfortunately passing both into `inputType` doesn't work. – Christopher Orr Mar 19 '10 at 11:21