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?
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);
来源:https://stackoverflow.com/questions/6164430/how-to-use-edittextpreference-as-a-masked-password-text-field