How to use EditTextPreference as a masked Password text field?

I have a very simple question: I have a EditTextPreference dialog which I want to use for getting the user's password and I want it to be masked.

How can I do that?

Answers


Here is a short 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.


android:inputType="numberPassword" doesn't work for me. Eclipse told me, that no String values are allowed for this attribute. So i used following:

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

This got me a EditTextPreference with a dotted textdisplay and a number keyboard for input.


If you want that the password mask persist also after device rotation is suffice to add the following imeOption:

in the edit text layout android:imeOptions="flagNoExtractUi"

or programmatically yourEditText.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI);


Need Your Help

wpf remove datagrid left padding

wpf wpf-controls wpfdatagrid

Can somebody please shed some light on how to get rid of the mysterious padding on the left?

What is a race condition?

multithreading concurrency terminology race-condition

When writing multi-threaded applications, one of the most common problems experienced are race conditions.