How to use EditTextPreference as a masked Password text field?

眉间皱痕 提交于 2019-12-03 00:56:09

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);

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!