How to use EditTextPreference as a text field with a masked password?

I have a very simple question:
I have an EditTextPreference dialog that I want to use to get the user password, and I want it to be masked.

How can i do this?

+42
android textview android-preferences
May 28 '11 at 21:24
source share
3 answers

Here is a quick example using xml:

 <EditTextPreference android:key="@string/key" android:title="@string/title" android:summary="@string/summary" android:inputType="textPassword" /> 

Or you can use numberPassword instead of textPassword .

+111
May 28 '11 at 21:32
source share

android:inputType="numberPassword" does not work for me. Eclipse told me that String values ​​are not allowed for this attribute. So I used the following:

 <EditTextPreference android:key="@string/key" android:title="@string/title" android:summary="@string/summary" android:inputType="number" android:password="true" /> 

This provided me with an EditTextPreference with a dashed textdisplay and numeric keypad for input.

+3
Jan 09 '13 at 13:33
source share

If you want the password mask to be preserved even after turning the device, just add the following imeOption :

in android:imeOptions="flagNoExtractUi" text editing layout android:imeOptions="flagNoExtractUi"

or programmatically yourEditText.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI);

0
Jun 26 '17 at 13:39 on
source share



All Articles