将EditText密码掩码字符更改为星号(*)

有没有办法将密码文本从点(。)改为星号(*)。

密码正在inputedittext。

<EditText android:id="@+id/passWord1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center" android:inputType="number" android:password="true"/> 

Solutions Collecting From Web of "将EditText密码掩码字符更改为星号(*)"

在您的xml文件中插入edittext,

 <EditText android:id="@+id/passWordEditText" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center" android:inputType="textPassword" android:password="true"/> 

和你的类文件继续从edittext中获取findViewById并为此实现,

 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 } } }; 
 <EditText android:id="@+id/passWord1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center" android:inputType="textPassword"//here is the change. check it once in your xml android:password="true"/> 

在eclipse中,当你在android:inputType处移动光标时,你点击Ctrl + Space会有提示。 然后你可以看到选项列表。 那里你可以selecttextPassword

如果你想看*代替. 然后检查这个Android: Asterisk Password Field

在Ram kiran发布的链接的帮助下得到答案

 text.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 } } }; 

对于android:inputType,有一种密码。

访问这个问题的stackoverflow,它会回答你的问题

如何更改密码字段以星号代替点号

检查下面的链接: –

如果你想看*代替。 然后检查这个Android:星号密码字段

http://codemanteau.com/post/code_11

EditText.setTransformationMethod(new PasswordTransformationMethod());

实施TextWatcher。

 EditText e = (EditText)findViewById(R.id.url_field); e.addTextChangedListener(new CustomTextWatcher(e)); 

//

 private class CustomTextWatcher implements TextWatcher { private EditText mEditText; public CustomTextWatcher(EditText e) { mEditText = e; } public void beforeTextChanged(CharSequence s, int start, int count, int after) { } public void onTextChanged(CharSequence s, int start, int before, int count) { } public void afterTextChanged(Editable s) { } } 

尝试这个

 android:inputType="textPassword"