本文介紹了將 EditText 密碼掩碼字符更改為星號 (*)的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
有什么方法可以將密碼文本從點(.)更改為星號(*).
Is there any way to change the password text from dot(.) to asterisk(*) .
密碼正在編輯文本中輸入.
Password is entering in edittext.
<EditText
android:id="@+id/passWord1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:inputType="number"
android:password="true"/>
推薦答案
在你的xml文件中插入edittext,
Insert edittext in your xml file,
<EditText
android:id="@+id/passWordEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:inputType="textPassword"/>
你的類文件繼續從edittext獲取findViewById并為此實現,
and your class file go on and get findViewById from edittext and implement for this,
EditText edittext = (EditText)findViewById(R.id.passWordEditText);
edittext.setTransformationMethod(new AsteriskPasswordTransformationMethod());
這個類實現了,
public class AsteriskPasswordTransformationMethod extends PasswordTransformationMethod {
@Override
public CharSequence getTransformation(CharSequence source, View view) {
return new PasswordCharSequence(source);
}
private class PasswordCharSequence implements CharSequence {
private CharSequence mSource;
public PasswordCharSequence(CharSequence source) {
mSource = source; // Store char sequence
}
public char charAt(int index) {
return '*'; // This is the important part
}
public int length() {
return mSource.length(); // Return default
}
public CharSequence subSequence(int start, int end) {
return mSource.subSequence(start, end); // Return default
}
}
};
如果您的代碼是 Kotlin,那么您必須制作單獨的 java 文件,然后您必須將 java 與 kotlin 代碼一起使用.
這篇關于將 EditText 密碼掩碼字符更改為星號 (*)的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!