[英]How can I mask the summary of an EditTextPreference when it is a masked password field?
我正在使用附加到我的EditTextPreference
的onPreferenceChangeListener
,它在摘要中顯示首選項的值。 這是它的樣子:
public boolean onPreferenceChange(Preference prePreference, Object objValue) {
if (prePreference instanceof EditTextPreference) {
//TODO: Check if password type and show chacraters
prePreference.setSummary(objValue.toString());
}
return true;
}
如果該字段是屏蔽密碼字段,我想在摘要中顯示默認密碼掩碼字符。 這是一個蒙面字段的示例:
<EditTextPreference
android:inputType="textPassword"
android:key="password"
android:title="@string/password" />
就像是:
EditText edit = ((EditTextPreference) prePreference).getEditText();
String pref = edit.getTransformationMethod().getTransformation(objValue.toString(), edit).toString();
prePreference.setSummary(pref);
更簡單的是,不要調用生成的bindPreferenceSummaryToValue
(進而調用setSummary
)來獲取密碼首選項。
請注意,您不應該在首選項中存儲密碼,而是在需要時從密碼中提示,從服務中獲取令牌,然后存儲令牌。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.